在 CoreData NSSet 上使用“filteredSetUsingPredicate”时崩溃(NSInvalidArgumentException:set 参数不是 NSSet)
Posted
技术标签:
【中文标题】在 CoreData NSSet 上使用“filteredSetUsingPredicate”时崩溃(NSInvalidArgumentException:set 参数不是 NSSet)【英文标题】:Crashing when using 'filteredSetUsingPredicate' on CoreData NSSet (NSInvalidArgumentException: set argument is not an NSSet) 【发布时间】: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
这种情况偶尔会发生一次,可能与我在后台上下文中所做的更新和删除有关(如果我坚持这个例子,添加或删除猫)。 知道如何保护我的应用程序不崩溃吗?任何对属性猫的访问都会导致崩溃。
【问题讨论】:
NSPredicate SUBQUERY results in: [NSMutableSet unionSet] set argument is not an NSSet的可能重复 【参考方案1】:您应该查看关系删除规则,确保其设置正确
【讨论】:
以上是关于在 CoreData NSSet 上使用“filteredSetUsingPredicate”时崩溃(NSInvalidArgumentException:set 参数不是 NSSet)的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 NSPredicate 通过 CoreData 中的 NSSet 属性的元素过滤对象?
无法转换“NSSet”类型的值?到预期的参数类型'Range<Int>'(使用CoreData)