ClientResetMode
@frozen
public enum ClientResetMode
An enum used to determines file recovery behavior in the event of a client reset.
Defaults to .recoverUnsyncedChanges.
See
RLMClientResetMode
-
All unsynchronized local changes are automatically discarded and the local state is automatically reverted to the most recent state from the server. Unsynchronized changes can then be recovered in the post-client-reset callback block.
If
.discardLocalis enabled but the client reset operation is unable to complete then the client reset process reverts to manual mode. Example: During a destructive schema change this mode will fail and invoke the manual client reset handler.See also
seeAlso
RLMClientResetBeforeBlockExample Usageuser.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges({ before in var recoveryConfig = Realm.Configuration() recoveryConfig.fileURL = myRecoveryPath do { before.writeCopy(configuration: recoveryConfig) // The copied realm could be used later for recovery, debugging, reporting, etc. } catch { // handle error } }, nil))See also
seeAlso
RLMClientResetAfterBlockExample Usage
user.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges( nil, { before, after in // This block could be used to add custom recovery logic, back-up a realm file, send reporting, etc. for object in before.objects(myClass.self) { let res = after.objects(myClass.self) if (res.filter("primaryKey == %@", object.primaryKey).first != nil) { // ...custom recovery logic... } else { // ...custom recovery logic... } } }))Declaration
Parameters
afterReseta function invoked after the client reset reset process has occurred.
beforea frozen copy of the local Realm state prior to client reset.
aftera live instance of the realm after client reset.
-
All unsynchronized local changes are automatically discarded and the local state is automatically reverted to the most recent state from the server. Unsynchronized changes can then be recovered in the post-client-reset callback block.
If
.discardUnsyncedChangesis enabled but the client reset operation is unable to complete then the client reset process reverts to manual mode. Example: During a destructive schema change this mode will fail and invoke the manual client reset handler.See also
seeAlso
RLMClientResetBeforeBlockExample Usageuser.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges({ before in var recoveryConfig = Realm.Configuration() recoveryConfig.fileURL = myRecoveryPath do { before.writeCopy(configuration: recoveryConfig) // The copied realm could be used later for recovery, debugging, reporting, etc. } catch { // handle error } }, nil))See also
seeAlso
RLMClientResetAfterBlockExample Usage
user.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges( nil, { before, after in // This block could be used to add custom recovery logic, back-up a realm file, send reporting, etc. for object in before.objects(myClass.self) { let res = after.objects(myClass.self) if (res.filter("primaryKey == %@", object.primaryKey).first != nil) { // ...custom recovery logic... } else { // ...custom recovery logic... } } }))Declaration
Parameters
afterReseta function invoked after the client reset reset process has occurred.
beforea frozen copy of the local Realm state prior to client reset.
aftera live instance of the realm after client reset.
-
The client device will download a realm realm which reflects the latest state of the server after a client reset. A recovery process is run locally in an attempt to integrate the server version with any local changes from before the client reset occurred.
The changes are integrated with the following rules:
- Objects created locally that were not synced before client reset will be integrated.
- If an object has been deleted on the server, but was modified on the client, the delete takes precedence and the update is discarded
- If an object was deleted on the client, but not the server, then the client delete instruction is applied.
- In the case of conflicting updates to the same field, the client update is applied.
If the recovery integration fails, the client reset process falls back to
ClientResetMode.manual. The recovery integration will fail if the “Client Recovery” setting is not enabled on the server. Integration may also fail in the event of an incompatible schema change.See also
seeAlso
RLMClientResetBeforeBlockExample Usageuser.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges({ before in var recoveryConfig = Realm.Configuration() recoveryConfig.fileURL = myRecoveryPath do { before.writeCopy(configuration: recoveryConfig) // The copied realm could be used later for recovery, debugging, reporting, etc. } catch { // handle error } }, nil))See also
seeAlso
RLMClientResetAfterBlockExample Usage
user.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges( nil, { before, after in // This block could be used to add custom recovery logic, back-up a realm file, send reporting, etc. for object in before.objects(myClass.self) { let res = after.objects(myClass.self) if (res.filter("primaryKey == %@", object.primaryKey).first != nil) { // ...custom recovery logic... } else { // ...custom recovery logic... } } }))Declaration
Parameters
afterReseta function invoked after the client reset reset process has occurred.
beforea frozen copy of the local Realm state prior to client reset.
aftera live instance of the realm after client reset.
-
The client device will download a realm with objects reflecting the latest version of the server. A recovery process is run locally in an attempt to integrate the server version with any local changes from before the client reset occurred.
The changes are integrated with the following rules:
- Objects created locally that were not synced before client reset will be integrated.
- If an object has been deleted on the server, but was modified on the client, the delete takes precedence and the update is discarded
- If an object was deleted on the client, but not the server, then the client delete instruction is applied.
- In the case of conflicting updates to the same field, the client update is applied.
If the recovery integration fails, the client reset process falls back to
ClientResetMode.discardUnsyncedChanges. The recovery integration will fail if the “Client Recovery” setting is not enabled on the server. Integration may also fail in the event of an incompatible schema change.See also
seeAlso
RLMClientResetBeforeBlockExample Usageuser.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges({ before in var recoveryConfig = Realm.Configuration() recoveryConfig.fileURL = myRecoveryPath do { before.writeCopy(configuration: recoveryConfig) // The copied realm could be used later for recovery, debugging, reporting, etc. } catch { // handle error } }, nil))See also
seeAlso
RLMClientResetAfterBlockExample Usage
user.configuration(partitionValue: "myPartition", clientResetMode: .discardUnsyncedChanges( nil, { before, after in // This block could be used to add custom recovery logic, back-up a realm file, send reporting, etc. for object in before.objects(myClass.self) { let res = after.objects(myClass.self) if (res.filter("primaryKey == %@", object.primaryKey).first != nil) { // ...custom recovery logic... } else { // ...custom recovery logic... } } }))Declaration
Parameters
afterReseta function invoked after the client reset reset process has occurred.
beforea frozen copy of the local Realm state prior to client reset.
aftera live instance of the realm after client reset.
-
See also
RLMClientResetModeManualThe manual client reset mode handler can be set in two places:
- As an ErrorReportingBlock argument in the ClientResetMode enum (`
ErrorReportingBlock?= nil`). - As an ErrorReportingBlock in the
SyncManager.errorHandlerproperty.
See also
RLMSyncManager.errorHandlerDuring an
RLMSyncErrorClientResetErrorthe block executed is determined by the following rules- If an error reporting block is set in
ClientResetModeand theSyncManager, theClientResetModeblock will be executed. - If an error reporting block is set in either the
ClientResetModeor theSyncManager, but not both, the single block will execute. - If no block is set in either location, the client reset will not be handled. The application will likely need to be restarted and unsynced local changes may be lost.
Note
TheSyncManager.errorHandleris still invoked under allRLMSyncErrors other thanRLMSyncErrorClientResetError.See also
seeAlsoRLMSyncErrorfor an exhaustive list.Declaration
Swift
@preconcurrency case manual(errorHandler: ErrorReportingBlock? = nil) - As an ErrorReportingBlock argument in the ClientResetMode enum (`
View on GitHub
Install in Dash