因此,我的数据库模型中的类别得到了更新(之前有 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:我应该制作一个新模型并将旧模型映射到新模型吗?