DittoConfig
public struct DittoConfig
extension DittoConfig: Codable
A configuration object for initializing a Ditto instance.
DittoConfig encapsulates all the parameters required to configure a Ditto
instance, including identity, connectivity, persistence, and experimental
features.
Important
This API is in preview and will become the standard way to initialize Ditto instances in v5, replacing the legacyDittoIdentity-based initialization.
-
The unique identifier for the Ditto database.
This must be a valid UUID string. You can find the database ID in the Ditto portal, or provide your own if you only need to sync with a small peers only.
Note
“Database ID” was previously referred to as “App ID” in older versions of the SDK.Declaration
Swift
public var databaseID: String -
The connectivity configuration for this Ditto instance.
Specifies how this instance discovers and connects to peers, including network settings and authentication options.
Declaration
Swift
public var connect: DittoConfigConnect -
The persistence directory used by Ditto to persist data.
This property accepts three types of values:
- Absolute path: A URL with an absolute file path (e.g.,
/Users/joe/some/path/to/my-project.ddb) - Relative path: A URL with a relative file path (e.g.,
some/path/to/my-project.ddb) - nil: Uses the default persistence directory
When a relative path is provided, it will be resolved relative to
defaultRootDirectory. Whennilis provided, Ditto will use a default directory name ofditto-{database-id}within thedefaultRootDirectorywhere{database-id}corresponds to the lowercase version of thedatabaseIDpassed alongside theDittoConfig.To access the final resolved absolute path after creating a Ditto instance, use
absolutePersistenceDirectory. This property will always return the effective absolute file path being used, regardless of whether you provided an absolute path, relative path, ornil.Note
“Database ID” was previously referred to as “App ID” in older versions of the SDK.
Note
It is not recommended to directly read from or write to this directory, as its structure and contents are managed by Ditto and may change in future versions.
Note
When
DittoLoggeris enabled, logs may be written to this directory even after a Ditto instance has been deallocated. Please refer to the documentation ofDittoLoggerfor more information.See also
See also
Declaration
Swift
public var persistenceDirectory: URL? - Absolute path: A URL with an absolute file path (e.g.,
-
Configuration for experimental features.
This property allows you to enable or configure features that are not yet part of the stable API. Use with caution, as experimental features may change or be removed in future releases.
Warning
Experimental functionality should not be used in production applications as it may be changed or removed at any time, and may not have the same security features.Declaration
Swift
public var experimental: DittoConfigExperimental -
Initializes a new
DittoConfiginstance with the specified parameters.Declaration
Swift
public init( databaseID: String, connect: DittoConfigConnect, persistenceDirectory: URL? = nil, experimental: DittoConfigExperimental = DittoConfigExperimental() ) -
Returns the default identifier for a Ditto instance.
This identifier is used when no explicit ID is provided. It is typically a constant UUID string that ensures a predictable default value. In most cases, you should provide your own unique identifier to avoid conflicts when syncing with other peers.
Declaration
Swift
public static func defaultDatabaseID() -> String -
Returns a default
DittoConfiginstance with standard settings.This is useful as a starting point or for quickly creating a basic configuration, but for production use you should customize the configuration as needed.
Declaration
Swift
public static var `default`: DittoConfig { get } -
Returns a copy of this
DittoConfigwith the specified modifications applied.This method allows you to create a new configuration by applying changes within the provided closure, leaving the original instance unchanged.
Declaration
Swift
public func updating(_ scope: (_ config: inout DittoConfig) -> Void) -> DittoConfigParameters
scopeA closure that receives an inout
DittoConfigto modify.Return Value
A new
DittoConfiginstance with the modifications applied.
-
Declaration
Swift
public init(from decoder: Decoder) throws -
Declaration
Swift
public func encode(to encoder: Encoder) throws