Umi and Satomi

シーズー犬うみと飼い主Satomiが楽しく生活してみます

Migrationの書き方

Realm Swift0.95.0でAPIが色々変わったので、メモ。

ChangeLog

realm-cocoa/CHANGELOG.md

Migrationの書き方

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

//↓↓↓↓

  let config = Realm.Configuration(
    schemaVersion: 1,
    migrationBlock: { migration, oldSchemaVersion in
      if (oldSchemaVersion < 1) {
      }
    })

  Realm.Configuration.defaultConfiguration = config

  let realm = Realm()
//↑↑↑↑

References

Official