首页 > 解决方案 > CoreData轻量级迁移后无法在新属性中保存数据

问题描述

我正在使用 CoreData,并且正在将新属性添加到实体中进行轻量级迁移。迁移过程运行良好.. 添加了新属性并且旧数据完好无损。但问题是新的 xcdatamodeld 版本显示新添加的属性为空白。当我向属性添加新数据时,不会存储数据。
这是我添加到正在创建持久容器对象的应用程序委托的代码:

        let container = NSPersistentContainer(name: "myAppName")
        let description = NSPersistentStoreDescription()
        description.shouldMigrateStoreAutomatically = true
        description.shouldInferMappingModelAutomatically = true
        container.persistentStoreDescriptions =  [description]

迁移正常进行,但来自旧数据模型的数据未显示在我的表格视图中,并且我添加到数据库中的新数据没有持久性。

标签: ioscore-datamigration

解决方案


推荐阅读