Reputation: 3711
I get the following exception An observer of NSManagedObjectContextDidSaveNotification illegally threw an exception. Objects saved = {
inserted = "{(\n)}";
updated = "{(\n <FJCDSeriesPreferences: 0x1744b30e0> (entity: SeriesPreferences; id: 0xd000000000700012 <x-coredata://29345DF0-9D92-410F-9305-84BFA1672BB9/SeriesPreferences/p28> ; data: {\n isFavourite = 0;\n region = us;\n series = \"0xd00000000d840010 <x-coredata://29345DF0-9D92-410F-9305-84BFA1672BB9/Series/p865>\";\n seriesID = 955129;\n})\n)}";
} and exception = [<FJCDSeriesPreferences 0x1744b30e0> valueForUndefinedKey:]: the entity SeriesPreferences is not key value coding-compliant for the key "program". with userInfo = {
NSTargetObjectUserInfoKey = "<FJCDSeriesPreferences: 0x1744b30e0> (entity: SeriesPreferences; id: 0xd000000000700012 <x-coredata://29345DF0-9D92-410F-9305-84BFA1672BB9/SeriesPreferences/p28> ; data: {\n isFavourite = 0;\n region = us;\n series = \"0xd00000000d840010 <x-coredata://29345DF0-9D92-410F-9305-84BFA1672BB9/Series/p865>\";\n seriesID = 955129;\n})";
NSUnknownUserInfoKey = program;
}
Here is the code that is causing the problem
-(void)contextDidUpdate:(NSNotification *)note{
NSManagedObjectContext *incomingContext = [note object];
NSDictionary *userInfo = [[note userInfo] copy];
if (self.context != incomingContext){
//Do not track
return;
}
predicateWithFormat:@"program.objectId IN %@", _objectsToFetch];
NSPredicate *programIDPredicate = [NSPredicate predicateWithFormat:@"%K like %@", @"program.objectId", _objectsToFetch ];
NSSet *inserted = [userInfo objectForKey:@"inserted"];
if ([inserted count]){
//objects have been inserted
self.insertedObjectsBlock([inserted allObjects]);
}
NSSet *deleted = [[[userInfo objectForKey:@"deleted"] copy ]filteredSetUsingPredicate:programIDPredicate];
if ([deleted count]){
//objects have been deleted
self.deletedObjectsBlock([deleted allObjects]);
}
NSSet *updated = [[[userInfo objectForKey:@"updated"] copy]filteredSetUsingPredicate:programIDPredicate];
if ([updated count]){
//objects have been updated
self.updatedObjectsBlock([updated allObjects]);
}
}
The issue is occurring around the predicate, since not all of the entities that are updating key-value compliant for the properties IM trying to access. What IM trying to do is to find objects that have changed and see if they are related to a particular relationship, in this case seeing if a preference is related to a program.
Upvotes: 1
Views: 1110
Reputation: 46718
There is an issue with your predicate. Without being able to poke it with a debugger directly, it appears that you are calling program.objectId
on an object that does not respond to those methods. If you are trying to access the NSManagedObjectID
then you have a typo as that method is objectID
not objectId
.
To catch this, I would suggest putting a break point before you use the predicate and print out what is in each of the sets and confirm you are getting what you are expecting to get.
BTW, those calls to -copy
are redundant and wasteful.
Upvotes: 2