Xcode 9中的Swift 4-如何实现轻量级核心数据迁移
我的核心数据将再更新一个属性,为了避免崩溃,我首先添加了一个新的模型版本,而且:Gulshan Kumar的解决方案很好。在我的例子中,它不起作用,因为容器已经有一个描述对象和设置Xcode 9中的Swift 4-如何实现轻量级核心数据迁移,swift,xcode,core-data,swift4,ios11,Swift,Xcode,Core Data,Swift4,Ios11,我的核心数据将再更新一个属性,为了避免崩溃,我首先添加了一个新的模型版本,而且:Gulshan Kumar的解决方案很好。在我的例子中,它不起作用,因为容器已经有一个描述对象和设置 You can achieve like this: let container = NSPersistentContainer(name: "YourDbModelName") let description = NSPersistentStoreDescription() description.should
You can achieve like this:
let container = NSPersistentContainer(name: "YourDbModelName")
let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = true
container.persistentStoreDescriptions = [description]
container.persistentStoreDescriptions = [description]
有效地删除了该对象,导致模型未加载。我曾经
container.persistentStoreDescriptions.append(description)
来自Gulshan Kumar的解决方案很好。在我的例子中,它不起作用,因为容器已经有一个描述对象和设置
container.persistentStoreDescriptions = [description]
有效地删除了该对象,导致模型未加载。我曾经
container.persistentStoreDescriptions.append(description)
谢谢我只是不知道自动迁移。@CLOX我尝试了你的答案,但仍然得到相同的错误,我使用的是Objective CThanks!我只是不知道自动迁移。@CLOX我试过你的答案,但仍然得到同样的错误,我使用的是Objective C