NSPredicate的2级钻取? [英] NSPredicate for 2-level drill-down?

查看:123
本文介绍了NSPredicate的2级钻取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

核心数据实体A与实体B具有一对多关系,其与实体C具有一对多关系,其具有两个属性:类型和值。

A core data entity A has a to-many relationship to entity B, which has a to-many relationship with entity C, which has two attributes:type and value.

A = >> B = >> C
(So:A.Bs.Cs.type,A.Bs.Cs.value)

A =>> B =>> C (So: A.Bs.Cs.type, A.Bs.Cs.value)

什么是 NSArray 过滤谓词所有A的任何B有任何C(类型=='test1'&&值=='test2')?

Whats an NSArray filter predicate for all A's that have any B that has any C that has (type=='test1' && value=='test2')?

我看到的子查询示例只有1级深度。

The subquery samples I've seen only go 1 level deep.

c> [NSCompoundPredicate andPredicateWithSubpredicates:]
with subpredicate 1)ANY Bs.Cs.type =='test1'和subpredicate 2)ANY Bs.Cs.value =='test2 ',但不返回任何内容。

I also tried [NSCompoundPredicate andPredicateWithSubpredicates:] with subpredicate 1) "ANY Bs.Cs.type=='test1'" and subpredicate 2) "ANY Bs.Cs.value=='test2'", but nothing is returned.

是的,我看过 NSPredicate

推荐答案

您需要使用 NSExpression + expressionForSubquery:usingIteratorVariable:predicate:或其中记录的表达式语法。

You need to use NSExpression +expressionForSubquery:usingIteratorVariable:predicate: or the expression syntax documented there.

我认为对于你的情况,

I think for your case it would be something like

(SUBQUERY(Bs, $b, 
   SUBQUERY($b.Cs, $c, $c.type=='text1' && $c.value='test2').@count != 0
 ).@count != 0)

这篇关于NSPredicate的2级钻取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆