swift - 错误:“此类不符合键值编码” - 对于任何键
问题描述
我在 Core Data 模型中保存了一个对象,但我发现该键对于任何键都不符合编码要求。
我尝试颠倒键的顺序,但我得到了任何一个,我试图改变 nome o 实体但也没有奏效。
let mediaEntity = NSEntityDescription.entity(forEntityName:
"Media", in: managedContext)
mediaEntity?.setValue(showMediaModel.popularity, forKey: "popularity")
mediaEntity?.setValue(showMediaModel.title, forKey: "title")
mediaEntity?.setValue(showMediaModel.type.rawValue, forKey: "type")
mediaEntity?.setValue(showMediaModel.id, forKey: "id")
do {
try managedContext.save()
} catch let error as NSError {
print("Could not save. \(error), \(error.userInfo)")
}
核心数据模型:
详细的消息错误是:
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<NSEntityDescription 0x6000008c02c0>
setValue:forUndefinedKey:]: this class is not key value coding-
compliant for the key popularity.'
我按照本教程在启动项目后添加了核心数据:https ://welcm.uk/blog/adding-core-data-to-an-existing-project-in-xcode-10-swift-4
解决方案
检查您的xcdatamodel
文件并确保“流行”的拼写与给出错误的行中的拼写匹配。
推荐阅读
- sql - SQL 删除前 1% 值的行
- excel - 获取多个表的两个匹配条件的标题
- javascript - 在 React js 中使用 Redux 连接 API 结果
- php - Shopware 基本设置不显示(“正在加载基本设置”)
- python - Alpine shell 找不到文件夹
- firebase - Vue Firebase 托管应用程序构建的文件不正确
- javascript - 未捕获的类型错误:无法读取 null Angular 6 的属性“addEventListener”
- git - 我用 -d 删除了一个分支,如何恢复/恢复它?
- modulo - 在 CGAL 上使用 mod 进行双打
- javascript - 在对象数组的嵌套对象数组中查找字符串