Realm Migration doesn't work

后端 未结 8 1198
天涯浪人
天涯浪人 2020-12-28 17:16
    let config = Realm.Configuration(
        // Set the new schema version. This must be greater than the previously used
        // version (if you\'ve never set a         


        
8条回答
  •  青春惊慌失措
    2020-12-28 17:45

    As long as you're in local development only, I'd recommend to reset your Realm database instead of doing a migration. Migrations are the way to go, if you have already shipped a version of your app with another schema and want to keep user data.

    You can delete the database by deleting the app from the simulator or the device. Alternatively you can use NSFileManager to delete the Realm file before accessing the database.

    let defaultPath = Realm.Configuration.defaultConfiguration.path!
    try NSFileManager.defaultManager().removeItemAtPath(defaultPath)
    

提交回复
热议问题