gpt4 book ai didi

ios - 抛出异常观察 NSManagedObjectContext 保存

转载 作者:行者123 更新时间:2023-11-29 10:28:07 31 4
gpt4 key购买 nike

我得到以下异常 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;
}

这是导致问题的代码

-(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 尝试访问的属性兼容。 IM 试图做的是查找已更改的对象,并查看它们是否与特定关系相关,在本例中查看偏好是否与程序相关。

最佳答案

您的谓词有问题。如果无法直接用调试器戳它,您似乎正在对不响应这些方法的对象调用 program.objectId。如果您尝试访问 NSManagedObjectID,那么您输入错误,因为该方法是 objectID 而不是 objectId

为了捕获这一点,我建议在使用谓词之前放置一个断点,并打印出每个集合中的内容,并确认您得到了您期望得到的结果。

顺便说一句,那些对 -copy 的调用是多余和浪费的。

关于ios - 抛出异常观察 NSManagedObjectContext 保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31150463/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com