Contents

CKSyncEngine.State

An object that manages the sync engine’s state.

Declaration

final class State

Overview

To reliably and consistently sync your app’s data, a sync engine keeps a record of several important pieces of data, such as server changes tokens (for databases and record zones), subscription identifiers, the most recent userRecordID, and so on. This class automatically manages that state on behalf of your app, but there are certain elements you can modify. For example, you control the list of pending changes to send to the iCloud servers and manipulate that list using the add(pendingDatabaseChanges:) and add(pendingRecordZoneChanges:) methods. If there aren’t any scheduled sync operations when you invoke these methods, the engine automatically schedules one.

An engine’s state changes periodically and, when it does, the sync engine dispatches a CKSyncEngine.Event.stateUpdate(_:) event to your delegate. The event contains an instance of CKSyncEngine.State.Serialization and, on receipt of such an event, it’s your responsibility to persist the serialized state to disk so that it’s available across app launches. On the next initialization of the sync engine, you provide the most recently persisted state as part of the engine’s configuration. For more information, see init(database:stateSerialization:delegate:).

Topics

Accessing pending changes

Manipulating pending changes

Serializing state

Instance Properties

See Also

Accessing the engine’s attributes