RLMMigration
@interface RLMMigration : NSObject
RLMMigration is the object passed into a user defined RLMMigrationBlock when updating the version of an RLMRealm instance.
This object provides access to the RLMSchema current to this migration.
-
Get the old RLMSchema for the migration. This is the schema which describes the RLMRealm before the migration is applied.
Declaration
Objective‑C
@property (readonly, nonatomic) RLMSchema *_Nonnull oldSchema;
Swift
var oldSchema: RLMSchema { get }
-
Get the new RLMSchema for the migration. This is the schema which describes the RLMRealm after applying a migration.
Declaration
Objective‑C
@property (readonly, nonatomic) RLMSchema *_Nonnull newSchema;
Swift
var newSchema: RLMSchema { get }
-
Enumerates objects of a given type in this Realm, providing both the old and new versions of each object. Objects properties can be accessed using keyed subscripting.
Warning
All objects returned are of a type specific to the current migration and should not be casted to className. Instead you should access them as RLMObjects 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
className
The name of the RLMObject class to enumerate.
-
Create an RLMObject of type
className
in 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) -> RLMObject
Parameters
className
The name of the RLMObject class to create.
value
The value used to populate the created 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 NSArray with one object for each persisted property. An exception will be thrown if any required properties are not present and no default is set.
-
Delete an object from a Realm during a migration. This can be called within
enumerateObjects:block:
.Declaration
Objective‑C
- (void)deleteObject:(nonnull RLMObject *)object;
Swift
func deleteObject(object: RLMObject)
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 RLMObject subclass no longer exists in your program, cleans up any remaining metadata for the class in the Realm file.
Declaration
Objective‑C
- (BOOL)deleteDataForClassName:(nonnull NSString *)name;
Swift
func deleteDataForClassName(name: String) -> Bool
Parameters
name
The name of the RLMObject class to delete.
Return Value
whether there was any data to delete.
-
Rename property of the given class from
oldName
tonewName
.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
className
Class for which the property is to be renamed. Must be present in both the old and new Realm schemas.
oldName
Old name for the property to be renamed. Must not be present in the new Realm.
newName
New name for the property to be renamed. Must not be present in the old Realm.