A skeleton app to be used as a reference for how to use the Realm Swift SDK. On the following project you see an example of the following use cases
- Connection state changes.
- User state changes.
- Sync error handling.
- Client reset.
├── SyncConnectionStateErrorReset
│ ├── Managers (Managers)
│ │ ├── AppManager.swift (Manager for App Auth)
│ │ ├── RealmManager.swift (Manager for Realm)
│ ├── Models (Includes all Realm models)
│ │ ├── Models.swift
│ ├── SyncConnectionStateErrorResetApp.swift (App Entry)
│ ├── AppViews.swift (Example Views)
└── other configuration files..
This project implements a simple example App which showcases the following use cases:
-
Listening for user state changes (logged in, logged out, or removed).
-
Listening if the underlying sync session state, is active, inactive or invalid.
-
Listening if the underlying sync session connection state is connecting, connected, disconnected.
-
Listening for sync errors using sync's error handler.
-
Listening for pre and post client resets blocks with
.recoverOrDiscardUnsyncedChanges
mode. -
This App also includes best practices to implement a Login/Register flow, handle the sync connection (error handler, connection state, session state, user state), handle sync and client reset and adds initial/update sync subscriptions to a flexible sync realm for a SwiftUI App.
-
Setting the default logger to
.all
, showing all the sync and realm access logs.
Realm Details:
- RealmSwift v10.41.1
- Device Sync type: Flexible
- XCode: 14.3.1
- iOS: 16.0
To sync Realm data you must first:
- Create an App Services App
- Enable Email/Password Authentication
- Enable Flexible Sync with Development Mode on.
- When Development Mode is enabled, queryable fields will be added automatically.
- Queryable fields used in this app:
_id
,storeId
,userId
.
After running the client and seeing the available collections in Atlas, set read/write permissions for all collections.
- Copy your Atlas App ID from the App Services UI.
- Paste the copied ID as the value of the existing variable
ATLAS_APP_ID
inSyncConnectionStateErrorReset/Managers/AppManager.swift
: - Run the example.