ios - NSManageObjectContext - 类不是键@count 的键值编码兼容

标签 ios core-data restkit xcode8

我有一个带有 RestKit 库和 CoreData 的 iOS 应用程序。自 Xcode8 以来,我可以看到比以前更多的日志,其中一个对我来说没有任何意义。

error: An observer of NSManagedObjectContextDidSaveNotification illegally threw an exception.  Objects saved = {
inserted = "{(\n)}";
managedObjectContext = "<_PFWeakReference: 0x600000621560>";
updated = "{(\n ... )}";
} 
and exception = [<_PFWeakReference 0x600000621560> valueForUndefinedKey:]: this class is not key value coding-compliant for the key @count. with userInfo = {
NSTargetObjectUserInfoKey = "<_PFWeakReference: 0x600000621560>";
NSUnknownUserInfoKey = "@count";

到目前为止,我能理解的是对 managedObjectContext 的弱引用(上面的错误)使用了错误的 key ,但我不知道如何调试它。

与此问题相关的所有 NSManagedObjects 似乎都是集合。大多数 NSSet 来自 OneToMany 或 ManyToMany 关系。

然后我找到了这个Apple documentation :

All the collection operators, with the exception of @count, require a key path to the right of the collection operator.

但是,我看不到我发出的当前使用此键的任何谓词或 CoreData 请求。

我重新生成了所有 NSManagedObject 模型并仔细检查了它们之间的所有反向关系,但这并没有帮助我摆脱它。

此应用运行良好,但我找不到任何解决方案来消除此警告。

最佳答案

我相信这已在 PR 2449 中修复,已合并到 development branch 中。该 PR 包含 this commit可以解决这个问题。

我不确定 PR 是否已经合并到 master 分支,所以不确定它是否可以通过 pod 获得。但是你可以在你的 podfile 中指定一个特定的提交,而不是一个版本。所以如果你指定这个:

pod 'RestKit', :git => 'https://github.com/RestKit/RestKit.git', :commit => '9cbba9eb1b490c3c5e2873c8fba8e9c0fec1bf07'

按照建议here它应该有效!

但也许那个提交与 Swift 3 不兼容,我不确定。但也许你没有使用 Swift 3...

关于ios - NSManageObjectContext - 类不是键@count 的键值编码兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39511997/

相关文章:

iphone - 滑动后 UITableViewCell 上的自定义按钮

iphone - 从相机拍摄照片后如何跳过 'retake and use' 选项

ios - 为什么 UICollectionView cellForItemat indexpath 会在一开始就为所有单元格调用

iphone - 过滤与核心数据的关系

ios - 无法使用 Xcode 7.2 使用 RestKit v0.10.3 存档 iOS 5.0 时代的项目

ios - 安装 RestKit 后使用未声明的标识符 'RKClient'

ios - NSFetchedResultsController 对负字符串值进行排序

ios - 显示包含核心数据的部分

core-data - TRUEPREDICATE 与 [NSPredicate predicateWithValue :YES]? 有何不同

ios - restkit 0.20 - (void) objectLoader didLoadObjects 和其他旧方法