manageObjectContext throwing unrecognized selector errors?
My application is a typical non-document based core data application. I have modified none of the pre-provided project code and have been using the AppDelegate files that Xcode provides by default (the project's not large enough to warrant much more).
Now, when I try to add an item to one of my core data stores with
NSManagedObject *colorItemObject = [NSEntityDescription insertNewObjectForEntityForName:@"ColorItem" inManagedObjectContext: [NSApp managedObjectContext]];
[colorItemObject setValue:[colorSetsArrayController valueForKeyPath:@"selection.colorSetName"] forK开发者_运维问答ey:@"parent"];
it throws an unrecognized selector exception:
-[_NSStateMarker managedObjectContext]: unrecognized selector sent to instance 0x100118290
Similar errors occur from using [self managedObjectContext]. What could be causing this?
I'm pretty sure
[NSApp managedObjectContext]
does not return a valid managedObjectContext
. Have you made a category to NSApplication
with a method called managedObjectContext
? If not, change that to
[self managedObjectContext]
and it should work. (I assumed your code is inside your app delegate.)
精彩评论