我得到下面的异常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; }
抛出异常观测的NSManagedObjectContext节省
这是导致该问题是围绕谓词中出现的问题
-(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]);
}
}
的代码,因为不是所有的都是实体更新兼容试图访问的IM属性的键值。即时消息试图做的是找到已更改的对象,并查看它们是否与特定关系相关,在这种情况下查看首选项是否与程序相关。
'_objectsToFetch'的类型是什么? –
_objectsToFetch是一个包含我想要获取的对象的对象ID的数组。 – TheM00s3