Configuration

public struct Configuration

A Realm.Configuration is used to describe the different options used to create a Realm instance.

Realm.Configuration instances are just plain Swift structs, and unlike Realm and Objects can be freely shared between threads. Creating configuration objects for class subsets (by setting the objectTypes property) can be expensive, and so you will normally want to cache and reuse a single configuration object for each distinct configuration that you are using rather than creating a new one each time you open a Realm.

  • Returns the default Realm.Configuration used to create Realms when no other configuration is explicitly specified (i.e. Realm()).

    Declaration

    Swift

    public static var defaultConfiguration: Configuration
  • Initializes a Realm.Configuration, suitable for creating new Realm instances.

    Declaration

    Swift

    public init(path: String?,
                        inMemoryIdentifier: String? = nil,
                        encryptionKey: NSData? = nil,
                        readOnly: Bool = false,
                        schemaVersion: UInt64 = 0,
                        migrationBlock: MigrationBlock? = nil,
                        objectTypes: [Object.Type]? = nil)

    Parameters

    path

    The path to the realm file.

    inMemoryIdentifier

    A string used to identify a particular in-memory Realm.

    encryptionKey

    64-byte key to use to encrypt the data.

    readOnly

    Whether the Realm is read-only (must be true for read-only files).

    schemaVersion

    The current schema version.

    migrationBlock

    The block which migrates the Realm to the current version.

    objectTypes

    The subset of Object subclasses persisted in the Realm.

  • Initializes a Realm.Configuration, suitable for creating new Realm instances.

    Declaration

    Swift

    public init(fileURL: NSURL? = NSURL(fileURLWithPath: RLMRealmPathForFile("default.realm"), isDirectory: false),
                inMemoryIdentifier: String? = nil,
                encryptionKey: NSData? = nil,
                readOnly: Bool = false,
                schemaVersion: UInt64 = 0,
                migrationBlock: MigrationBlock? = nil,
                deleteRealmIfMigrationNeeded: Bool = false,
                objectTypes: [Object.Type]? = nil)

    Parameters

    fileURL

    The local URL to the realm file.

    inMemoryIdentifier

    A string used to identify a particular in-memory Realm.

    encryptionKey

    64-byte key to use to encrypt the data.

    readOnly

    Whether the Realm is read-only (must be true for read-only files).

    schemaVersion

    The current schema version.

    migrationBlock

    The block which migrates the Realm to the current version.

    deleteRealmIfMigrationNeeded

    If true, recreate the Realm file with the new schema if a migration is required.

    objectTypes

    The subset of Object subclasses persisted in the Realm.