SUBQUERY in core data

2019-01-24 19:31发布

I can't understand what's wrong with my predication. I have the next database scheme:

DataItem(color_ids) <->> (dataItem)Color

Where Color contains colorID(int).

I tried to get

all DataItems that contain colorID == 5.

I have used the next predicate:

SUBQUERY(color_ids, $sub, $sub.colorID==5).@count > 0

Thanks for your help.

1条回答
孤傲高冷的网名
2楼-- · 2019-01-24 20:18

You don't need SUBQUERY for this. In fact, you almost never need SUBQUERY; it is extremely rare to find a situation where it is the correct thing to use.

You can do this instead:

[NSPredicate predicateWithFormat:@"ANY color_ids.colorID == 5"];
查看更多
登录 后发表回答