【发布时间】:2019-02-01 22:16:51
【问题描述】:
所以我的数据库模型中的类别得到了更新(之前有 4 个,现在是 7 个),我想用新对象更新核心数据。
我试图应用这个:https://developer.apple.com/documentation/coredata/using_lightweight_migration
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// Create the coordinator and store
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.appendingPathComponent("x.sqlite")
let options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true]
var failureReason = "There was an error creating or loading the application's saved data."
do {
try coordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: options)
} catch {
// Report any error we got.}
但是我的数据是一样的……它没有随着新的类别而更新。 有什么帮助吗?谢谢.. PS:要不要做一个新模型,把旧模型映射到新模型?
【问题讨论】:
-
您需要添加一个新的模型版本,然后选择该模型版本作为当前模型版本。
-
除了我做了什么?
-
我的评论有意义吗? @MohamedLee
标签: ios swift core-data core-data-migration lightweight-processes