Replicator

public final class Replicator

A replicator for replicating document changes between a local database and a target database. The replicator can be bidirectional or either push or pull. The replicator can also be one-short or continuous. The replicator runs asynchronously, so observe the status property to be notified of progress.

  • Activity level of a replicator.

    • stopped: The replicator is finished or hit a fatal error.
    • offline: The replicator is offline as the remote host is unreachable.
    • connecting: The replicator is connecting to the remote host.
    • idle: The replicator is inactive waiting for changes or offline.
    • busy: The replicator is actively transferring data.
    See more

    Declaration

    Swift

    public enum ActivityLevel : UInt8
  • Progress of a replicator. If total is zero, the progress is indeterminate; otherwise, dividing the two will produce a fraction that can be used to draw a progress bar.

    See more

    Declaration

    Swift

    public struct Progress
  • Combined activity level and progress of a replicator.

    See more

    Declaration

    Swift

    public struct Status
  • Initializes a replicator with the given configuration.

    Declaration

    Swift

    public init(config: ReplicatorConfiguration)

    Parameters

    config

    The configuration.

  • The replicator’s configuration.

    Declaration

    Swift

    public var config: ReplicatorConfiguration { get }
  • The replicator’s current status: its activity level and progress. Observable.

    Declaration

    Swift

    public var status: Status { get }
  • The SSL/TLS certificate received when connecting to the server.

    Declaration

    Swift

    public var serverCertificate: SecCertificate? { get }
  • Starts the replicator. This method returns immediately; the replicator runs asynchronously and will report its progress through the replicator change notification.

    Declaration

    Swift

    public func start()
  • Starts the replicator with an option to reset the local checkpoint of the replicator. When the local checkpoint is reset, the replicator will sync all changes since the beginning of time from the remote database. This method returns immediately; the replicator runs asynchronously and will report its progress through the replicator change notification.

    Declaration

    Swift

    public func start(reset: Bool)

    Parameters

    reset

    Resets the local checkpoint before starting the replicator.

  • Stops a running replicator. This method returns immediately; when the replicator actually stops, the replicator will change its status’s activity level to .stopped and the replicator change notification will be notified accordingly.

    Declaration

    Swift

    public func stop()
  • Resets the local checkpoint of the replicator, meaning that it will sync all changes since the beginning of time from the remote database. This can only be called when the replicator is in a stopped state.

    Declaration

    Swift

    @available(*, deprecated, message: "Use start(reset:﹚ instead.")
    public func resetCheckpoint()
  • Adds a replicator change listener. Changes will be posted on the main queue.

    Declaration

    Swift

    @discardableResult
    public func addChangeListener(
        _ listener: @escaping (ReplicatorChange) -> Void) -> ListenerToken

    Parameters

    listener

    The listener to post changes.

    Return Value

    An opaque listener token object for removing the listener.

  • Adds a replicator change listener with the dispatch queue on which changes will be posted. If the dispatch queue is not specified, the changes will be posted on the main queue.

    Declaration

    Swift

    @discardableResult
    public func addChangeListener(withQueue queue: DispatchQueue?,
        _ listener: @escaping (ReplicatorChange) -> Void) -> ListenerToken

    Parameters

    queue

    The dispatch queue.

    listener

    The listener to post changes.

    Return Value

    An opaque listener token object for removing the listener.

  • Adds a document replication event listener. The document replication events will be posted on the main queue.

    According to performance optimization in the replicator, the document replication listeners need to be added before starting the replicator. If the listeners are added after the replicator is started, the replicator needs to be stopped and restarted again to ensure that the listeners will get the document replication events.

    Declaration

    Swift

    @discardableResult
    public func addDocumentReplicationListener(
        _ listener: @escaping (DocumentReplication) -> Void) -> ListenerToken

    Parameters

    listener

    The listener to post document replication events.

    Return Value

    An opaque listener token object for removing the listener.

  • Adds a document replication event listener with the dispatch queue on which events will be posted. If the dispatch queue is not specified, the document replication events will be posted on the main queue.

    According to performance optimization in the replicator, the document replication listeners need to be added before starting the replicator. If the listeners are added after the replicator is started, the replicator needs to be stopped and restarted again to ensure that the listeners will get the document replication events.

    Declaration

    Swift

    @discardableResult
    public func addDocumentReplicationListener(withQueue queue: DispatchQueue?,
        _ listener: @escaping (DocumentReplication) -> Void) -> ListenerToken

    Parameters

    queue

    The dispatch queue.

    listener

    The listener to post document replication events.

    Return Value

    An opaque listener token object for removing the listener.

  • Removes a change listener with the given listener token.

    Declaration

    Swift

    public func removeChangeListener(withToken token: ListenerToken)

    Parameters

    token

    The listener token.

  • Gets a set of document Ids, who have revisions pending push. This API is a snapshot and results may change between the time the call was made and the time the call returns.

    Declaration

    Swift

    public func pendingDocumentIds() throws -> Set<String>

    Return Value

    A set of document Ids, each of which has one or more pending revisions

  • Checks if the document with the given ID has revisions pending push. This API is a snapshot and results may change between the time the call was made and the time the call returns.

    Declaration

    Swift

    public func isDocumentPending(_ documentID: String) throws -> Bool

    Parameters

    documentID

    The ID of the document to check

    Return Value

    true if the document has one or more revisions pending, false otherwise