Jaa*_*nus 10 core-data nsset nspredicate
建立:
我有一个与B具有to-many关系的Core Data对象A.调用关系"items".因此,a.items返回与A关联的所有Bs.
现在,我有一个手动组成的B对象的NSSet"itemSet".
我想做以下事情:
return all A objects whose "items" relation exactly matches itemSet
Run Code Online (Sandbox Code Playgroud)
如何为此构造谓词?我试过这个:
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"(ALL items in %@)", itemSet];
Run Code Online (Sandbox Code Playgroud)
但那只是给了我Unsupported predicate (null).
这个:
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"(items in %@)", itemSet];
Run Code Online (Sandbox Code Playgroud)
告诉我unimplemented SQL generation for predicate.有趣,但没有帮助.
那么用一组过滤关系的正确方法是什么?
Mar*_*n R 20
以下谓词可以工作:
[NSPredicate predicateWithFormat:@"(items.@count == %d) AND (SUBQUERY(items, $x, $x IN %@).@count == %d)",
itemSet.count, itemSet, itemSet.count];
Run Code Online (Sandbox Code Playgroud)
谓词首先检查项目的数量是否等于给定的大小itemSet,然后检查成员的项目数量itemSet是否也等于itemSet.如果两者都是真的,则items必须等于itemSet.
| 归档时间: |
|
| 查看次数: |
5059 次 |
| 最近记录: |