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 legacy DittoIdentity-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. When nil is provided, Ditto will use a default directory name of ditto-{database-id} within the defaultRootDirectory where {database-id} corresponds to the lowercase version of the databaseID passed alongside the DittoConfig.

    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, or nil.

    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 DittoLogger is enabled, logs may be written to this directory even after a Ditto instance has been deallocated. Please refer to the documentation of DittoLogger for more information.

    Declaration

    Swift

    public var persistenceDirectory: URL?
  • 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 DittoConfig instance 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 DittoConfig instance 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 DittoConfig with 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) -> DittoConfig

    Parameters

    scope

    A closure that receives an inout DittoConfig to modify.

    Return Value

    A new DittoConfig instance with the modifications applied.

Codable

  • Declaration

    Swift

    public init(from decoder: Decoder) throws
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws