Ditto
public class Ditto
Ditto
is the entry point for accessing Ditto-related functionality.
-
A string containing the semantic version of the Ditto SDK. Example:
4.4.3
.Declaration
Swift
public class var version: String { get }
-
An optional delegate that will be called with SDK lifecycle information if defined.
Declaration
Swift
public var delegate: DittoDelegate? { get set }
-
Configure a custom identifier for this peer.
When using
presence
, each remote peer is represented by a short UTF-8 “device name”. By default this will be a truncated version of the device’s hostname.Changes to this property after
startSync()
was called will only take effect after the next restart of sync. The value does not need to be unique among peers. Device names longer than 24 bytes will be truncated oncestartSync()
is called.Declaration
Swift
public var deviceName: String { get set }
-
The site ID that the instance of
Ditto
is using as part of its identity.Declaration
Swift
public var siteID: UInt64 { get }
-
The persistence directory used by Ditto to persist data.
It is not recommended to directly read or write to this directory as its structure and contents are managed by Ditto and may change in future versions.
When
DittoLogger
is enabled, logs may be written to this directory even after a Ditto instance was deallocated. Please refer to the documentation ofDittoLogger
for more information.Declaration
Swift
public var persistenceDirectory: URL { get }
-
The Ditto application ID.
Declaration
Swift
public var appID: String { get }
-
A flag indicating whether or not the SDK has been activated with a valid license token.
Declaration
Swift
public var activated: Bool { get }
-
A flag indicating whether or not sync is active. Use
startSync()
to active andstopSync()
to deactivate sync.Declaration
Swift
public var isSyncActive: Bool { get }
-
A flag indicating whether or not the Ditto data is encrypted.
Declaration
Swift
public var isEncrypted: Bool { get }
-
Provides access to authentication information and methods for logging on to Ditto Cloud.
Declaration
Swift
public internal(set) var auth: DittoAuthenticator? { get }
-
Provides visibility into to disk usage of this Ditto instance.
Declaration
Swift
public var diskUsage: DiskUsage { get }
-
Provides access to the SDK’s store functionality.
Declaration
Swift
public let store: DittoStore
-
Provides access to the SDK’s sync functionality.
Declaration
Swift
public let sync: DittoSync
-
Provides access to the SDK’s presence functionality.
Declaration
Swift
public let presence: DittoPresence
-
Provides access to the SDK’s small peer info functionality.
Declaration
Swift
public let smallPeerInfo: DittoSmallPeerInfo
-
Provides access to the SDK’s experimental functionality.
Declaration
Swift
public let experimental: DittoExperimental
-
The
DispatchQueue
that will be used to deliver delegate events. Defaults toDispatchQueue.main
.Declaration
Swift
public var delegateEventQueue: DispatchQueue { get set }
-
Assign a new transports configuration. By default peer-to-peer transports (Bluetooth, WiFi and AWDL) are enabled. You may use this property to alter the configuration at any time. Sync will not begin until
startSync()
is called.Declaration
Swift
public var transportConfig: DittoTransportConfig { get set }
-
Convenience method to update the current transport config of the receiver.
Invokes the block with a copy of the current transport config which you can alter to your liking. The updated transport config is then set on the receiver.
You may use this method to alter the configuration at any time. Sync will not begin until
startSync
is invoked.Declaration
Swift
public func updateTransportConfig(block: (inout DittoTransportConfig) -> Void)
-
Indicates whether or not history tracking is enabled. Default is
false
.History tracking is experimental and shouldn’t be used in production.
Declaration
Swift
public var isHistoryTrackingEnabled: Bool { get }
-
Initializes a new
Ditto
.Declaration
Swift
public convenience init( identity: DittoIdentity = .offlinePlayground(), persistenceDirectory directory: URL? = nil )
Parameters
identity
Provide the identity of the entity that is interacting with Ditto.
persistenceDirectory
The directory that will be used to persist Ditto data.
-
Initializes a new
Ditto
.Declaration
Swift
public convenience init( identity: DittoIdentity = .offlinePlayground(), historyTrackingEnabled: Bool, persistenceDirectory: URL? = nil )
Parameters
identity
Provide the identity of the entity that is interacting with Ditto.
historyTrackingEnabled
Whether or not you want history tracking enabled.
persistenceDirectory
The directory that will be used to persist Ditto data.
-
Activate an offline
DITDitto
instance by setting a license token. You cannot sync data across instances using an offline (Development, OfflinePlayground, Manual or SharedKey) identity before you have activated the associatedDitto
instance.Throws
DittoSwiftError
.Declaration
Swift
public func setOfflineOnlyLicenseToken(_ licenseToken: String) throws
Parameters
licenseToken
The license token to activate the
Ditto
instance with, which you can find on the Ditto portal (https://portal.ditto.live). -
Starts the network transports. Ditto will connect to other devices.
By default Ditto will enable all peer-to-peer transport types. On iOS this means Bluetooth, WiFi and AWDL. The network configuration can be customized using the
setTransportConfig
method.Performance of initial sync when bootstrapping a new peer can be improved by calling
disableSyncWithV3()
before callingstartSync()
. Only do this when all peers in the mesh are known to be running Ditto v4 or higher.Throws
DittoSwiftError
.Declaration
Swift
public func startSync() throws
-
Stops all network transports.
You may continue to use the database locally but no data will sync to or from other devices.
Declaration
Swift
public func stopSync()
-
Request bulk status information about the transports. This is mostly intended for statistical or debugging purposes.
Throws
DittoSwiftError
.Declaration
Swift
public func transportDiagnostics() throws -> DittoTransportDiagnostics
Return Value
An instance of
DittoTransportDiagnostics
. -
A string identifying the version of the DittoSwift SDK.
Declaration
Swift
public var sdkVersion: String { get }
-
Removes all sync metadata for any remote peers which aren’t currently connected. This method shouldn’t usually be called. Manually running garbage collection often will result in slower sync times. Ditto automatically runs a garbage a collection process in the background at optimal times.
Manually running garbage collection is typically only useful during testing if large amounts of data are being generated. Alternatively, if an entire data set is to be evicted and it’s clear that maintaining this metadata isn’t necessary, then garbage collection could be run after evicting the old data.
Declaration
Swift
public func runGarbageCollection()
-
Disable sync with peers running version 3 or lower of the Ditto SDK.
Required for the execution of mutating DQL statements.
This setting spreads to other peers on connection. Those peers will in turn spread it further until all peers in the mesh take on the same setting. This is irreversible and will persist across restarts of the Ditto instance.
Calling this method before
startSync()
is recommended whenever possible. This improves performance of initial sync when this peer has never before connected to a Ditto mesh for which sync with v3 peers is disabled.Throws
DittoSwiftError
if the operation fails.Declaration
Swift
public func disableSyncWithV3() throws
-
Request information about Ditto peers in range of this device.
This method returns an observer which should be held as long as updates are required. A newly registered observer will have a peers update delivered to it immediately. Then it will be invoked repeatedly when Ditto devices come and go, or the active connections to them change.
Declaration
Swift
@available(*, deprecated, message: "Use `self.presence.observe(﹚` instead.") public func observePeers(callback: @escaping (Array<DittoRemotePeer>) -> ()) -> DittoObserver
-
Request information about Ditto peers in range of this device.
This method returns an observer which should be held as long as updates are required. A newly registered observer will have a peers update delivered to it immediately. From then on it will be invoked repeatedly when Ditto devices come and go, or the active connections to them change.
Declaration
Swift
@available(*, deprecated, message: "Use `self.presence.observe(﹚` instead.") public func observePeersV2(callback: @escaping (String) -> ()) -> DittoObserver
-
A Combine publisher that shows all the remote connected peers.
See moreDeclaration
Swift
@available(*, deprecated, message: "Replaced by `DittoPresence.GraphPublisher`.") struct RemotePeersPublisher : Publisher
-
A Combine publisher that shows all the remote connected peers.
Declaration
Swift
@available(*, deprecated, message: "Replaced by `self.presence.graphPublisher(﹚`.") func remotePeersPublisher() -> RemotePeersPublisher
Return Value
A
RemotePeersPublisher
which has an output of[DittoRemotePeer]