Skip to content

Commit

Permalink
examples fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alazier committed Jan 16, 2015
1 parent 8b04aa5 commit 48808dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions examples/ios/objc/Migration/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// 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
[RLMRealm setSchemaVersion:3 withMigrationBlock:^(RLMMigration *migration, NSUInteger oldSchemaVersion) {
RLMMigrationBlock migrationBlock = ^(RLMMigration *migration, NSUInteger oldSchemaVersion) {
if (oldSchemaVersion < 1) {
[migration enumerateObjects:Person.className block:^(RLMObject *oldObject, RLMObject *newObject) {
if (oldSchemaVersion < 1) {
Expand All @@ -75,7 +75,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}];
}
NSLog(@"Migration complete.");
}];
};

// set the schema verion and migration block for the defualt realm
[RLMRealm setDefaultRealmSchemaVersion:3 withMigrationBlock:migrationBlock];

// now that we have called `setSchemaVersion:withMigrationBlock` opening an outdated Realm will automatically
// perform the migration and opening the Realm will succeed
Expand All @@ -96,6 +99,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[NSFileManager defaultManager] removeItemAtPath:realmv2Path error:nil];
[[NSFileManager defaultManager] copyItemAtPath:v2Path toPath:realmv2Path error:nil];

// set schemave versions and migration blocks form Realms at each path
[RLMRealm setSchemaVersion:3 forRealmAtPath:realmv1Path withMigrationBlock:migrationBlock];
[RLMRealm setSchemaVersion:3 forRealmAtPath:realmv2Path withMigrationBlock:migrationBlock];

// manully migration v1Path, v2Path is migrated implicitly on access
[RLMRealm migrateRealmAtPath:realmv1Path];

Expand Down
6 changes: 5 additions & 1 deletion examples/ios/swift/Migration/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
println("Migration complete.")
}
RLMRealm.setSchemaVersion(3, withMigrationBlock: migrationBlock)
RLMRealm.setDefaultRealmSchemaVersion(3, withMigrationBlock: migrationBlock)

// print out all migrated objects in the default realm
// migration is performed implicitly on Realm access
Expand All @@ -109,6 +109,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
NSFileManager.defaultManager().removeItemAtPath(realmv2Path, error: nil)
NSFileManager.defaultManager().copyItemAtPath(v2Path, toPath: realmv2Path, error: nil)

// set the schema version and migration blocks for our custom path realms
RLMRealm.setSchemaVersion(3, forRealmAtPath: realmv1Path, withMigrationBlock: migrationBlock)
RLMRealm.setSchemaVersion(3, forRealmAtPath: realmv2Path, withMigrationBlock: migrationBlock)

// migrate realms at realmv1Path manually, realmv2Path is migrated automatically on access
RLMRealm.migrateRealmAtPath(realmv1Path)

Expand Down

0 comments on commit 48808dd

Please sign in to comment.