Ditto
public class Ditto
Ditto
is the entry point for accessing Ditto-related functionality.
-
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 the current device.
When using
observePeers()
, 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. It does not need to be unique among peers. Configure the device name before callingtryStartSync()
. If it is too long it may be truncated.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 }
-
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
tryStartSync()
to active andstopSync()
to deactivate sync.Declaration
Swift
public var isSyncActive: 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 access to the SDK’s store functionality.
Declaration
Swift
public var store: DittoStore { get }
-
The
DispatchQueue
that will be used to deliver delegate events. Defaults toDispatchQueue.main
.Declaration
Swift
public var delegateEventQueue: DispatchQueue { get set }
-
Undocumented
Declaration
Swift
public var transportConfig: DittoTransportConfig { get set }
-
Assign a new transports configuration. By default peer-to-peer transports (Bluetooth, WiFi and AWDL) are enabled.
You may use this method to alter the configuration at any time, however sync will not begin until
startSync
is called.Declaration
Swift
@available(*, deprecated, message: "use the newly introduced property `transportconfig` instead.") public func setTransportConfig(config: DittoTransportConfig)
-
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 init( identity: DittoIdentity = .offlinePlayground(), historyTrackingEnabled: Bool, persistenceDirectory directory: 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 a
Ditto
instance by setting an access license. You cannot sync data across instances using an offline (Development, OfflinePlayground, Manual or SharedKey) identity before you have activated the associatedDitto
instance.Declaration
Swift
@available(*, deprecated, message: "use `setOfflineOnlyLicenseToken` instead") public func setAccessLicense(_ license: String)
Parameters
license
The license to activate the
Ditto
instance with, which you can find on the Ditto portal (https://portal.ditto.live). -
Activate a
Ditto
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
@available(*, deprecated, message: "use `setOfflineOnlyLicenseToken` instead") public func setLicenseToken(_ 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). -
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.Declaration
Swift
@available(*, deprecated, message: "use `tryStartSync` instead") public func startSync()
-
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.Throws
DittoSwiftError
.Declaration
Swift
public func tryStartSync() 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
. -
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
public func observePeers(callback: @escaping (Array<DittoRemotePeer>) -> ()) -> DittoObserver
-
Undocumented
Declaration
Swift
public func observePeersV2(callback: @escaping (String) -> ()) -> DittoObserver
-
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()
-
A Combine publisher that shows all the remote connected peers.
See moreDeclaration
Swift
struct RemotePeersPublisher : Publisher
-
A Combine publisher that shows all the remote connected peers.
Declaration
Swift
func remotePeersPublisher() -> RemotePeersPublisher
Return Value
A
RemotePeersPublisher
which has an output of[DittoRemotePeer]