According to the Realm documentation, there are some samples of how you do a migration in Realm.
From the sample code, there's this:
// define a migration block
// you can define this inline, but we will reuse this to migrate realm files from multiple versions
// to the most current version of our data model
RLMMigrationBlock migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
if (oldSchemaVersion < 1) {
[migration enumerateObjects:Person.className block:^(RLMObject *oldObject, RLMObject *newObject) {
if (oldSchemaVersion < 1) {
// combine name fields into a single field
newObject[@"fullName"] = [NSString stringWithFormat:@"%@ %@", oldObject[@"firstName"], oldObject[@"lastName"]];
}
}];
}
if (oldSchemaVersion < 2) {
[migration enumerateObjects:Person.className block:^(RLMObject *oldObject, RLMObject *newObject) {
// give JP a dog
if ([newObject[@"fullName"] isEqualToString:@"JP McDonald"]) {
Pet *jpsDog = [[Pet alloc] initWithValue:@[@"Jimbo", @(AnimalTypeDog)]];
[newObject[@"pets"] addObject:jpsDog];
}
}];
}
if (oldSchemaVersion < 3) {
[migration enumerateObjects:Pet.className block:^(RLMObject *oldObject, RLMObject *newObject) {
// convert type string to type enum if we have outdated Pet object
if (oldObject && oldObject.objectSchema[@"type"].type == RLMPropertyTypeString) {
newObject[@"type"] = @([Pet animalTypeForString:oldObject[@"type"]]);
}
}];
}
NSLog(@"Migration complete.");
It looks like you declare a block in which you enumerate objects and manually update the schema.