RLMMigration
@interface RLMMigration : NSObject
RLMMigration instances encapsulate information intended to facilitate a schema migration.
A RLMMigration instance is passed into a user-defined RLMMigrationBlock 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
RLMSchema. This is the schema which describes the Realm before the migration is applied.Declaration
Objective‑C
@property (readonly, nonatomic) RLMSchema *_Nonnull oldSchema;Swift
var oldSchema: RLMSchema { get } -
Returns the new
RLMSchema. This is the schema which describes the Realm after the migration is applied.Declaration
Objective‑C
@property (readonly, nonatomic) RLMSchema *_Nonnull newSchema;Swift
var newSchema: RLMSchema { get }
-
Enumerates all the objects of a given type in the Realm, providing both the old and new versions of each object. Within the block, object properties can only be accessed using keyed subscripting.
Warning
All objects returned are of a type specific to the current migration and should not be cast to
className. Instead, treat them asRLMObjects and use keyed subscripting to access properties.Declaration
Objective‑C
- (void)enumerateObjects:(nonnull NSString *)className block:(nonnull RLMObjectMigrationBlock)block;Swift
func enumerateObjects(className: String, block: RLMObjectMigrationBlock)Parameters
classNameThe name of the
RLMObjectclass to enumerate. -
Creates and returns an
RLMObjectinstance of typeclassNamein the Realm being migrated.Declaration
Objective‑C
- (nonnull RLMObject *)createObject:(nonnull NSString *)className withValue:(nonnull id)value;Swift
func createObject(className: String, withValue value: AnyObject) -> RLMObjectParameters
classNameThe name of the
RLMObjectclass to create.valueThe value used to populate the object. This can be any key-value coding compliant object, or an array or dictionary returned from the methods in
NSJSONSerialization, or anNSArraycontaining 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. -
Deletes an object from a Realm during a migration.
It is permitted to call this method from within the block passed to
-[enumerateObjects:block:].Declaration
Objective‑C
- (void)deleteObject:(nonnull RLMObject *)object;Swift
func deleteObject(object: RLMObject)Parameters
objectObject 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
RLMObjectsubclass no longer exists in your program, any remaining metadata for the class will be removed from the Realm file.Declaration
Objective‑C
- (BOOL)deleteDataForClassName:(nonnull NSString *)name;Swift
func deleteDataForClassName(name: String) -> BoolParameters
nameThe name of the
RLMObjectclass 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
Objective‑C
- (void)renamePropertyForClass:(nonnull NSString *)className oldName:(nonnull NSString *)oldName newName:(nonnull NSString *)newName;Swift
func renamePropertyForClass(className: String, oldName: String, 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
RLMMigration Class Reference