Native Swift Template
The native iOS Swift template supports the latest Swift features:
- SwiftUI
- Combine
Publisher
SceneUI
andSceneDelegate
flow
Also, this template demonstrates Mobile SDK offline features.
This template defines two initialization classes: AppDelegate
and SceneDelegate
. These classes interact to enable a dynamic arrangement of multiple windows.
Architecturally, this template uses strict model-view separation, with one model class per view class. Model classes implement the ObservableObject
protocol, while view classes implement the View
protocol.
AppDelegate
manages high-level setup—app launch and the UISceneSession
lifecycle. In Mobile SDK terms, AppDelegate
in this template
- Initializes Mobile SDK
- Registers and unregisters push notification services, if implemented
- Sets up IDP, if implemented
As in earlier Mobile SDK templates, you can customize settings in the application(_:didFinishLaunchingWithOptions:)
method of AppDelegate
.
SceneDelegate
handles the life cycles of scenes in the UISceneSession
container. The following initializer method configures a scene and adds it to the scene collection.
After instantiating the scene as a UIWindow
, this method registers a handler for current user changes. If the CurrentUserChange
event occurs, the template resets the view state by setting up the root view controller.
Later, in the sceneDidBecomeActive(_:)
method, the template reinitializes the app view state and resets the root view controller. If no user is logged into Salesforce, the template requires the user to log in before it performs this reset.
Models for the template’s views differ in how they download Salesforce information.
-
The
AccountsListModel
class uses the Mobile SyncSyncManager
publisher to sync down information for all accounts. When the response arrives, the publisher stores the information in a SmartStore soup, according to the sync and SmartStore configurations.To send account information to the view, the
loadFromSmartStore()
method uses the SmartStore publisher to extract the data from the SmartStore soup. -
The
ContactsForAccountModel
class uses aRestClient
factory method to create the REST request.To send a request to Salesforce and process the asynchronous response, this model uses the
RestClient
shared Combine publisher.This model stores details for all displayed contacts in a published array. See Handling REST Requests.
Views include a list of accounts, and list and detail views of related contacts. The Account list view displays a list of account names. Selecting an account brings up a list view of the account’s contacts. When the customer selects a contact record, a detail view displays the contact’s information.
- Accounts
- Account | Contacts
- Contact | Details
- Account | Contacts
Views serve to configure a visual interface that imports and presents data from the related model object. To handle taps on view items, the view object sets up a navigation link to the destination view and passes it the necessary data. Here’s the definition for the Accounts list view.
- Scenes (Apple Developer Documentation)
- Ray Wenderlich’s MVVM with Combine Tutorial for iOS
- https://www.vadimbulavin.com/ios-13-ipados-app-life-cycle-with-uiscene-scene-session-and-scene-delegate/