DittoSync

public class DittoSync

Provides access to sync related functionality of Ditto.

Starting and Stopping Sync

  • Starts the network transports. Ditto will connect to other devices.

    By default Ditto will enable all peer-to-peer transport types. On Apple devices, this means BluetoothLE, WiFi/LAN, and AWDL. The default network configuration can be modified with updateTransportConfig() or replaced via the transportConfig property.

    Performance of initial sync when bootstrapping a new peer can be improved by calling disableSyncWithV3() before calling start(). Only do this when all peers in the mesh are known to be running Ditto v4 or higher.

    Throws

    DittoError.

    Declaration

    Swift

    public func start() throws
  • Stops all network transports.

    You may continue to use the Ditto store locally but no data will sync to or from other devices.

    Declaration

    Swift

    public func stop()
  • A flag indicating whether or not sync is active. Use start() to activate and stop() to deactivate sync.

    Declaration

    Swift

    public var isActive: Bool { get }

Managing Sync Subscriptions

  • Returns all currently active sync subscriptions.

    Declaration

    Swift

    public private(set) var subscriptions: Set<DittoSyncSubscription> { get }
  • Installs and returns a sync subscription for a query, configuring Ditto to receive updates from other peers for documents matching that query. The passed in query must be a SELECT query, otherwise a store error with queryNotSupported reason is thrown.

    Throws

    DittoError > .storeError(.queryInvalid) if query string is not valid DQL.

    Throws

    DittoError > .storeError(.queryArgumentsInvalid) if arguments dictionary is not valid (contains unsupported types).

    Throws

    DittoError > .storeError(.queryNotSupported) if query is not a SELECT query.

    Throws

    May throw other DittoErrors.

    Declaration

    Swift

    @discardableResult
    public func registerSubscription(
        query: String,
        arguments: Dictionary<String, Any?>? = nil
    ) throws -> DittoSyncSubscription

    Return Value

    An active SyncSubscription for the passed in query and arguments. You’ll have to keep it to be able to cancel the sync subscription. Otherwise it will remain active until the owning Ditto object goes out of scope.