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 .discardLocal is 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 RLMClientResetBeforeBlock Example Usage

    user.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 RLMClientResetAfterBlock

    Example 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

    Swift

    @preconcurrency
    case discardLocal(beforeReset: (@Sendable (_ before: Realm) -> Void)? = nil,
                      afterReset: (@Sendable (_ before: Realm, _ after: Realm) -> Void)? = nil)

    Parameters

    afterReset

    a function invoked after the client reset reset process has occurred.

    before

    a frozen copy of the local Realm state prior to client reset.

    after

    a 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 .discardUnsyncedChanges is 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 RLMClientResetBeforeBlock Example Usage

    user.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 RLMClientResetAfterBlock

    Example 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

    Swift

    @preconcurrency
    case discardUnsyncedChanges(beforeReset: (@Sendable (_ before: Realm) -> Void)? = nil,
                                afterReset: (@Sendable (_ before: Realm, _ after: Realm) -> Void)? = nil)

    Parameters

    afterReset

    a function invoked after the client reset reset process has occurred.

    before

    a frozen copy of the local Realm state prior to client reset.

    after

    a 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:

    1. Objects created locally that were not synced before client reset will be integrated.
    2. If an object has been deleted on the server, but was modified on the client, the delete takes precedence and the update is discarded
    3. If an object was deleted on the client, but not the server, then the client delete instruction is applied.
    4. 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 RLMClientResetBeforeBlock Example Usage

    user.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 RLMClientResetAfterBlock

    Example 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

    Swift

    @preconcurrency
    case recoverUnsyncedChanges(beforeReset: (@Sendable (_ before: Realm) -> Void)? = nil,
                                afterReset: (@Sendable (_ before: Realm, _ after: Realm) -> Void)? = nil)

    Parameters

    afterReset

    a function invoked after the client reset reset process has occurred.

    before

    a frozen copy of the local Realm state prior to client reset.

    after

    a 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:

    1. Objects created locally that were not synced before client reset will be integrated.
    2. If an object has been deleted on the server, but was modified on the client, the delete takes precedence and the update is discarded
    3. If an object was deleted on the client, but not the server, then the client delete instruction is applied.
    4. 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 RLMClientResetBeforeBlock Example Usage

    user.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 RLMClientResetAfterBlock

    Example 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

    Swift

    @preconcurrency
    case recoverOrDiscardUnsyncedChanges(beforeReset: (@Sendable (_ before: Realm) -> Void)? = nil,
                                         afterReset: (@Sendable (_ before: Realm, _ after: Realm) -> Void)? = nil)

    Parameters

    afterReset

    a function invoked after the client reset reset process has occurred.

    before

    a frozen copy of the local Realm state prior to client reset.

    after

    a live instance of the realm after client reset.

  • See also

    RLMClientResetModeManual

    The manual client reset mode handler can be set in two places:

    1. As an ErrorReportingBlock argument in the ClientResetMode enum (`ErrorReportingBlock? = nil`).
    2. As an ErrorReportingBlock in the SyncManager.errorHandler property.

See also

RLMSyncManager.errorHandler

    During an RLMSyncErrorClientResetError the block executed is determined by the following rules

    • If an error reporting block is set in ClientResetMode and the SyncManager, the ClientResetMode block will be executed.
    • If an error reporting block is set in either the ClientResetMode or the SyncManager, 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

    The SyncManager.errorHandler is still invoked under all RLMSyncErrors other than RLMSyncErrorClientResetError.

    See also

    seeAlso RLMSyncError for an exhaustive list.

Declaration

Swift

@preconcurrency
case manual(errorHandler: ErrorReportingBlock? = nil)