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
Realm
which 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
Realm
instances which require migration. After registering your migration block, Realm will call your block automatically as needed.Declaration
Swift
public func setDefaultRealmSchemaVersion(schemaVersion: UInt64, migrationBlock: MigrationBlock)
Parameters
version
The current schema version.
block
The 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
Realm
which 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
Realm
instances 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
version
The current schema version.
realmPath
The path of the Realms to migrate.
block
The block which migrates the Realm to the current version.
-
Get the schema version for a Realm at a given path.
Declaration
Swift
public func schemaVersionAtPath(realmPath: String, encryptionKey: NSData? = nil, error: NSErrorPointer = nil) -> UInt64?
Return Value
The version of the Realm at
realmPath
ornil
if 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
path
The path of the Realm to migrate.
encryptionKey
Optional 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
nil
if the migration was successful, or anNSError
object 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
configuration
The 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
nil
if the migration was successful, or anNSError
object that describes the problem that occured otherwise.
-
Returns whether both objects are equal. Objects are considered equal when they are both from the same Realm and point to the same underlying object in the database.
Declaration
Swift
public func == <T: Object>(lhs: T, rhs: T) -> Bool
-
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