核心数据到多个NSPredicate与AND [英] Core data to-many NSPredicate with AND

查看:167
本文介绍了核心数据到多个NSPredicate与AND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为即搜即得类型的搜索栏写一个查询。我想做的是查询Kind,并返回任何有一个LocalName的类型('name'LIKE%@ AND localeIdentifier ==%@)。



<如果我只搜索名称(所以忽略localeIdentifier),我可以这样做:

  ANY本地化.name LIKE%@ 

我想要的是更像

 任何本地化(名称LIKE%@ AND localeIdentifier ==%@)

总而言之,搜索Kind,多对多关系localized中的任何一个项目都应该匹配name和localeIdentifier。



解决方案

你想要的是一个子查询。在谓词格式语法中:

  SUBQUERY(self.localized,$ x,$ x.name LIKE%@ AND $ x.localeIdentifier ==%@)。@ count> 0 

其中 SUBQUERY self.localized 集合中匹配第三个参数中的谓词的实例。 种类此SUBQUERY表达式非空的实例(即 @count> 0 )符合您所需的条件。



SUBQUERY表达式是在OS X 10.5中引入的。


I'm trying to write a query for the find-as-you-type search bar. What I want to do is query "Kind", and return any Kinds for which there is a LocalName with ('name' LIKE %@ AND localeIdentifier == %@).

If I'm only searching the names (so ignoring the localeIdentifier), I could do something like this:

ANY localized.name LIKE %@

What I want is something more like

ANY localized.(name LIKE %@ AND localeIdentifier == %@)

To sum up, searching "Kind", any one item in the to-many relationship "localized" should match both name and localeIdentifier.

Any ideas for the correct syntax of this?

解决方案

What you want is a subquery. In predicate format syntax:

SUBQUERY(self.localized, $x, $x.name LIKE %@ AND $x.localeIdentifier == %@).@count > 0

where the SUBQUERY expression returns a collection of instances in the self.localized collection that match the predicate in the third argument. Kind instances for which this SUBQUERY expression is non-empty (ie @count > 0) match your desired criteria.

The SUBQUERY expression was introduced in OS X 10.5.

这篇关于核心数据到多个NSPredicate与AND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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