Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSManageObjectContext - Class is not key value coding-compliant for the key @count

I've got an iOS app with RestKit library and CoreData. Since Xcode8, I can see way more logs than before and one of them doesn't make any sense to me.

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";

So far, what I can understand is that a weak reference to the managedObjectContext (above in the error) is using a wrong key, but I can't figured out how to debug it.

All the NSManagedObjects related to this issue seems to be collections. Mostly NSSet from a OneToMany or ManyToMany relationship.

Then I found this Apple documentation:

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

However, I can't see any predicate or CoreData request I made that currently use this key.

I regenerated all my NSManagedObject models and double check all the inverse relations between them but it didn't help me to get rid of it.

This app is running fine but I couldn't find any solution to remove this warning.

like image 970
Ben Avatar asked Sep 15 '16 13:09

Ben


1 Answers

I believe this was fixed in PR 2449, that has been merged into development branch. That PR contains this commit that seams to address the issue.

I am not sure if the PR has been merged into master branch, so not sure if it is available via pods. But you can in your podfile specify a specific commit, rather than a version. So if you specify this:

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

as suggested here it should work!

But maybe that commit is not compatible with Swift 3, I am not sure about that. But maybe you are not using Swift 3...

like image 92
Sajjon Avatar answered Sep 18 '22 12:09

Sajjon