问题描述
我正在尝试为即搜即得类型的搜索栏写一个查询。我想做的是查询Kind,并返回任何有一个LocalName的类型('name'LIKE%@ AND 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!