Functions
The following functions are available globally.
-
Specify a schema version and an associated migration block which is applied when opening the default Realm with an old schema version.
Before you can open an existing
Realmwhich has a different on-disk schema from the schema defined in your object interfaces, you must provide a migration block which converts from the disk schema to your current object schema. At the minimum your migration block must initialize any properties which were added to existing objects without defaults and ensure uniqueness if a primary key property is added to an existing object.You should call this method before accessing any
Realminstances which require migration. After registering your migration block, Realm will call your block automatically as needed.Warning
Unsuccessful migrations will throw exceptions when the migration block is applied. This will happen in the following cases:
- The given `schemaVersion` is lower than the target Realm's current schema version. - A new property without a default was added to an object and not initialized during the migration. You are required to either supply a default value or to manually populate added properties during a migration.Declaration
Swift
public func setDefaultRealmSchemaVersion(schemaVersion: UInt64, migrationBlock: MigrationBlock)Parameters
versionThe current schema version.
blockThe block which migrates the Realm to the current version.
-
Specify a schema version and an associated migration block which is applied when opening a Realm at the specified path with an old schema version.
Before you can open an existing
Realmwhich has a different on-disk schema from the schema defined in your object interfaces, you must provide a migration block which converts from the disk schema to your current object schema. At the minimum your migration block must initialize any properties which were added to existing objects without defaults and ensure uniqueness if a primary key property is added to an existing object.You should call this method before accessing any
Realminstances which require migration. After registering your migration block, Realm will call your block automatically as needed.Declaration
Swift
public func setSchemaVersion(schemaVersion: UInt64, realmPath: String, migrationBlock: MigrationBlock)Parameters
versionThe current schema version.
realmPathThe path of the Realms to migrate.
blockThe block which migrates the Realm to the current version.
-
Get the schema version for a Realm at a given path. - parameter realmPath: Path to a Realm file. - parameter encryptionKey: Optional 64-byte encryption key for encrypted Realms. - parameter error: If an error occurs, upon return contains an
NSErrorobject that describes the problem. If you are not interested in possible errors, omit the argument, or pass innil.Declaration
Swift
public func schemaVersionAtPath(realmPath: String, encryptionKey: NSData? = nil, error: NSErrorPointer = nil) -> UInt64?Parameters
realmPathPath to a Realm file.
encryptionKeyOptional 64-byte encryption key for encrypted Realms.
errorIf an error occurs, upon return contains an
NSErrorobject that describes the problem. If you are not interested in possible errors, omit the argument, or pass innil.Return Value
The version of the Realm at
realmPathornilif the version cannot be read. -
Performs the registered migration block on a Realm at the given path.
This method is called automatically when opening a Realm for the first time and does not need to be called explicitly. You can choose to call this method to control exactly when and how migrations are performed.
Declaration
Swift
public func migrateRealm(path: String, encryptionKey: NSData? = nil) -> NSError?Parameters
pathThe path of the Realm to migrate.
encryptionKeyOptional 64-byte encryption key for encrypted Realms. If the Realms at the given path are not encrypted, omit the argument or pass in
nil.Return Value
nilif the migration was successful, or anNSErrorobject that describes the problem that occured otherwise. -
Performs the configuration’s migration block on the Realm created by the given configuration.
This method is called automatically when opening a Realm for the first time and does not need to be called explicitly. You can choose to call this method to control exactly when and how migrations are performed.
Declaration
Swift
public func migrateRealm(configuration: Realm.Configuration = Realm.Configuration.defaultConfiguration) -> NSError?Parameters
configurationThe Realm.Configuration used to create the Realm to be migrated, and containing the schema version and migration block used to perform the migration.
Return Value
nilif the migration was successful, or anNSErrorobject that describes the problem that occured otherwise.
-
Returns whether the two object schemas are equal.
Declaration
Swift
public func ==(lhs: ObjectSchema, rhs: ObjectSchema) -> Bool
-
Returns whether the two properties are equal.
Declaration
Swift
public func ==(lhs: Property, rhs: Property) -> Bool
-
Returns whether the two realms are equal.
Declaration
Swift
public func ==(lhs: Realm, rhs: Realm) -> Bool
-
Returns whether the two schemas are equal.
Declaration
Swift
public func ==(lhs: Schema, rhs: Schema) -> Bool
-
Returns whether the two sort descriptors are equal.
Declaration
Swift
public func ==(lhs: SortDescriptor, rhs: SortDescriptor) -> Bool
View on GitHub
Install in Dash
Functions Reference