【发布时间】:2016-07-31 11:55:25
【问题描述】:
假设我有 NSManagedObject Zoo,他有连接 oneToMany 到 'Cat' 命名的猫,这个连接是 NSSet。 当我使用函数'filteredSetUsingPredicate'时,我遇到了以下代码崩溃:
Zoo *zoo = //intance of our zoo with all the animals - from core data
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"catSize == Big"];
NSArray *arrayOfCats = [zoo.cats filteredSetUsingPredicate:predicate];
崩溃堆栈如下:
Terminating app due to an uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableSet unionSet:]: set argument is not an NSSet'
Crashed: com.apple.main-thread
1 CoreFoundation 0x180f51798 -[NSMutableSet unionSet:] + 96
2 CoreData 0x182f24154 -[_NSFaultingMutableSet willReadWithContents:] + 716
3 CoreData 0x182f05f10 -[_NSFaultingMutableSet count] + 28
4 Foundation 0x181a93828 -[NSSet(NSPredicateSupport) filteredSetUsingPredicate:] + 68
这种情况偶尔会发生一次,可能与我在后台上下文中所做的更新和删除有关(如果我坚持这个例子,添加或删除猫)。 知道如何保护我的应用程序不崩溃吗?任何对属性猫的访问都会导致崩溃。
【问题讨论】:
标签: ios objective-c core-data nspredicate nsset