Migration
public final class Migration
Migration
instances encapsulate information intended to facilitate a schema migration.
A Migration
instance is passed into a user-defined MigrationBlock
block when updating
the version of a Realm. This instance provides access to the old and new database schemas, the
objects in the Realm, and provides functionality for modifying the Realm during the migration.
-
Returns the old schema, describing the Realm before applying a migration.
Declaration
Swift
public var oldSchema: Schema { return Schema(rlmMigration.oldSchema) }
-
Returns the new schema, describing the Realm after applying a migration.
Declaration
Swift
public var newSchema: Schema { return Schema(rlmMigration.newSchema) }
-
Enumerates all the objects of a given type in this Realm, providing both the old and new versions of each object. Object properties can be accessed using subscripting.
Declaration
Swift
public func enumerate(objectClassName: String, _ block: MigrationObjectEnumerateBlock)
Parameters
objectClassName
The name of the
Object
class to enumerate.block
The block providing both the old and new versions of an object in this Realm.
-
Creates and returns an
Object
of typeclassName
in the Realm being migrated.Declaration
Swift
public func create(className: String, value: AnyObject = [:]) -> MigrationObject
Parameters
className
The name of the
Object
class to create.value
The value used to populate the created object. This can be any key-value coding compliant object, or an array or dictionary returned from the methods in
NSJSONSerialization
, or anArray
containing one element for each persisted property. An exception will be thrown if any required properties are not present and those properties were not defined with default values.Return Value
The newly created object.
-
Deletes an object from a Realm during a migration.
It is permitted to call this method from within the block passed to
enumerate(_:block:)
.Declaration
Swift
public func delete(object: MigrationObject)
Parameters
object
Object to be deleted from the Realm being migrated.
-
Deletes the data for the class with the given name.
All objects of the given class will be deleted. If the
RLMObject
subclass no longer exists in your program, any remaining metadata for the class will be removed from the Realm file.Declaration
Swift
public func deleteData(objectClassName: String) -> Bool
Parameters
objectClassName
The name of the
Object
class to delete.Return Value
A Boolean value indicating whether there was any data to delete.
-
Renames a property of the given class from
oldName
tonewName
.Declaration
Swift
public func renamePropertyForClass(className: String, oldName: String, newName: String)
Parameters
className
The name of the class whose property should be renamed. This class must be present in both the old and new Realm schemas.
oldName
The old name for the property to be renamed. There must not be a property with this name in the class as defined by the new Realm schema.
newName
The new name for the property to be renamed. There must not be a property with this name in the class as defined by the old Realm schema.