
func application(_ application: UIApplication,dIDFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { print("HERE") Realm.Configuration.defaultConfiguration = Realm.Configuration( schemaVersion: 1,migrationBlock: { migration,oldSchemaVersion in if (oldSchemaVersion < 1) { migration.enumerateObjects(ofType: WeekReport.classname()) { oldobject,newObject in newObject!["inspectorname"] = "" } } }) return true} 但似乎在我的错误发生之前没有调用dIDFinishLaunchingWithOptions.
在多视图控制器中我让letm =尝试!领域().我运行应用程序时Xcode中断了:
“Migration is required due to the following errors:
– Property ‘WeekReport.inspectorname’ has been added.” UserInfo={NSLocalizedDescription=Migration is required due to the following errors:
– Property ‘WeekReport.inspectorname’ has been added.,Error Code=10}: file /library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.63/src/swift/
怎么没有调用迁移blick? “HERE”从未打印过……
我应该在视图控制器中以不同的方式定义领域吗?
解决方法 如果你写letm = try!视图控制器中的Realm()作为实例变量,它将在应用程序之前调用:来自Storyboard的dIDFinishLaunchingWithOptions.要解决这个问题,你可以使用lazy var realm = try! Realm()代替.延迟创建一个实例变量,直到访问该变量. 总结以上是内存溢出为你收集整理的ios – 没有调用领域迁移全部内容,希望文章能够帮你解决ios – 没有调用领域迁移所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)