Migration
public struct 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.
-
Enumerates all the objects of a given type in this Realm, providing both the old and new versions of each object. Properties on an object can be accessed using subscripting.
Declaration
Swift
public func enumerateObjects(ofType typeName: String, _ block: MigrationObjectEnumerateBlock)Parameters
objectClassNameThe name of the
Objectclass to enumerate.blockThe block providing both the old and new versions of an object in this Realm.
-
Creates and returns an
Objectof typeclassNamein the Realm being migrated.The
valueargument is used to populate the object. It can be a key-value coding compliant object, an array or dictionary returned from the methods inNSJSONSerialization, or anArraycontaining one element for each managed property. An exception will be thrown if any required properties are not present and those properties were not defined with default values.When passing in an
Arrayas thevalueargument, all properties must be present, valid and in the same order as the properties defined in the model.Declaration
Swift
@discardableResult public func create(_ typeName: String, value: Any = [:]) -> MigrationObjectParameters
classNameThe name of the
Objectclass to create.valueThe value used to populate the created object.
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
objectAn 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
Objectsubclass no longer exists in your program, any remaining metadata for the class will be removed from the Realm file.Declaration
Swift
@discardableResult public func deleteData(forType typeName: String) -> BoolParameters
objectClassNameThe name of the
Objectclass to delete.Return Value
A Boolean value indicating whether there was any data to delete.
-
Renames a property of the given class from
oldNametonewName.Declaration
Swift
public func renameProperty(onType typeName: String, from oldName: String, to newName: String)Parameters
classNameThe name of the class whose property should be renamed. This class must be present in both the old and new Realm schemas.
oldNameThe 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.
newNameThe 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.
View on GitHub
Install in Dash
Migration Structure Reference