Migration

public final class Migration

Migration is the object passed into a user-defined MigrationBlock when updating the version of a Realm instance.

This object provides access to the previous and current Schemas for this migration.

  • The migration’s old Schema, describing the Realm before applying a migration.

    Declaration

    Swift

    public var oldSchema: Schema { return Schema(rlmMigration.oldSchema) }
  • The migration’s new Schema, describing the Realm after applying a migration.

    Declaration

    Swift

    public var newSchema: Schema { return Schema(rlmMigration.newSchema) }
  • Enumerates 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.

  • Create an Object of type className 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 object used to populate the new Object. This can be any key/value coding compliant object, or a JSON object such as those returned from the methods in NSJSONSerialization, or an Array with one object for each persisted property. An exception will be thrown if any required properties are not present and no default is set.

    Return Value

    The created object.

  • Delete an object from a Realm during a migration. This can be called within 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. This deletes all objects of the given class, and if the Object subclass no longer exists in your program, cleans up any remaining metadata for the class in the Realm file.

    Declaration

    Swift

    public func deleteData(objectClassName: String) -> Bool

    Parameters

    objectClassName

    The name of the Object class to delete.

    Return Value

    true if there was any data to delete.