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
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
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.
1func sceneWillEnterForeground(_ scene: UIScene){2 // Called as the scene transitions from the background to the foreground.3 // Use this method to undo the changes made on entering the background.4 self.initializeAppViewState()5 AuthHelper.loginIfRequired{6 self.setupRootViewController()7}8}
Model Classes
Models for the template’s views differ in how they download Salesforce information.
The AccountsListModel class uses the Mobile Sync SyncManager 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.
This model stores details for all displayed contacts in a published array. See Handling REST Requests.
View Classes
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
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.