我正在尝试从匹配条件的相关实体获取记录计数
我有一个实体匹配,它与许多实体集相关。我想计算有多少组将特定匹配的属性“set_finished”设置为“是”。我正在尝试这样做:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY set_finished == YES"]; NSUInteger numberOfFinishedSets = [[[match valueForKeyPath:@"sets"] FilteredArrayUsingPredicate:predicate ] count];
第二行因此错误而崩溃,我不明白。有人能为我解释一下吗?谢谢。
2010-12-20 13:17:13.814 DartScorer[2154:207] * 终止 应用程序由于未捕获的异常 'NSInvalidArgumentException',原因: '-[_NSFaultingMutableSet FilteredArrayUsingPredicate:]: 无法识别的选择器发送到实例 0x617fb20'
I have an entity matches which has a related to-many entity sets. I want to get a count of how many sets have the attribute 'set_finished' set to YES for a particular match. I'm trying to do this with:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY set_finished == YES"];
NSUInteger numberOfFinishedSets = [[[match valueForKeyPath:@"sets"] filteredArrayUsingPredicate:predicate ] count];
The second line crashes with this error, which I don't understand. Can anyone shed some light on this for me? Thanks.
2010-12-20 13:17:13.814
DartScorer[2154:207] * Terminating
app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[_NSFaultingMutableSet
filteredArrayUsingPredicate:]:
unrecognized selector sent to instance
0x617fb20'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用
filteredSetUsingPredicate:
而不是filteredArrayUsingPredicate
,因为该对象是一个集合,而不是一个数组。You should use
filteredSetUsingPredicate:
instead offilteredArrayUsingPredicate
since the object is a set, not an array._NSFaultingMutableSet 是一种空集(如果您要打印该集,您将看到 xcode 打印实体名称而不是其内容。它这样做是因为:
我认为你应该创建一个 Set 来保存你想要过滤的对象,然后过滤你创建的数组。
希望有帮助
沙尼
_NSFaultingMutableSet is kind of an empty set (if you will print the set you will see that xcode prints the entity name but not its content. it does that because :
i think you should create a Set to hold the objects you want to filter, and then filter the array tou have created.
hope it helps
shani
这只会返回有多少对象的计数,而不是实际从磁盘检索对象并对其进行计数。
This will just return the count of how many objects there are instead of actually retrieving the objects from disk and counting them.
尝试将字符串 YES 用单引号 "... 'YES' " 括起来
(假设该字段包含字符串 'YES' 和 'NO' 而不是 1 | 0)
Try wrapping the string YES in single quotes "... 'YES' "
(assuming the field contains the strings 'YES' and 'NO' and not 1 | 0)