我的核心数据将再更新一个属性,为避免崩溃,我首先添加了一个新的模型版本,但由于我的应用程序委托者没有持久的协调器,因此在哪里可以将迁移选项设置为true
答案 0 :(得分:0)
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Your Core data modeld name")
let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = true
container.persistentStoreDescriptions = [description]
//--------------------------------------------------------//
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()