Realm Migration doesn't work

后端 未结 8 1181
天涯浪人
天涯浪人 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:41

    I had a similar issue happening where my app would crash despite the fact that I added the default migration code in didFinishLaunchingWithOptions

    The problem was that I was indeed initializing an instance of Realm in my first view controller as a class level property. So removing that class level realm object from my first ViewController fixed the issue.

    import UIKit
    import RealmSwift
    
    class ViewController: UIViewController{
      let db = try! Realm() // Removing this solved my issue
    
      func doSomething(){
        let db = try! Realm() // Placed this here instead
      }
    }
    

    I instead created the object inside the function that needed it, which is a better approach anyway.

提交回复
热议问题