我的核心数据会更新一个属性,为了避免崩溃,我首先添加了一个新的模型版本,此外:👇👇👇
关于这个问题的大部分关键是改变:
coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
options: nil 在代码中
options:[NSMigratePersistentStoresAutomaticallyOption:true, NSInferMappingModelAutomaticallyOption: true]
但是在我的 appdelegate.swift 中,我找不到任何“persistentStoreCoordinator”,那么我可以在我的版本中迁移 CoreData 吗?
最佳答案
You can achieve like this:
let container = NSPersistentContainer(name: "YourDbModelName")
let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = true
container.persistentStoreDescriptions = [description]
关于Xcode 9 中的 Swift 4 - 如何轻量级迁移 Core Data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51519516/