NSPredicate 表达式中 SUBQUERY 的快速解释
关于 Apple 的 SUBQUERY 关键字的文档似乎为零,我在 SO 或 Google 上找不到关于它的简单解释。这是一个阴谋! ;)
拜托,内部圈子里的人可以快速解释一下它的语法,以便我可以使用它吗?
SUBQUERY(Bs, $x, $x IN %@)
谢谢
There appears to be zero documentation about the SUBQUERY keyword from Apple and I can't find a simple explanation about it on SO or on Google. It's a conspiracy! ;)
Please, could someone from the inner-circle please just provide a quick explanation of its syntax so I can use it?
SUBQUERY(Bs, $x, $x IN %@)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于不太明白文档内容的人来说,
SUBQUERY
本质上是这样的:并且可以(简单地)像这样实现:
所以简而言之,
SUBQUERY
code> 基本上是获取一个对象集合,并根据SUBQUERY
的谓词表达式过滤出各种对象,然后返回结果集合。 (谓词本身可以包含其他SUBQUERY
)示例:
And for people who don't quite get what the documentation is saying, a
SUBQUERY
is essentially this:And could (simplistically) be implemented like this:
So in a nutshell, a
SUBQUERY
is basically taking a collection of objects and filtering out various objects based on the predicate expression of theSUBQUERY
, and returning the resulting collection. (And the predicate itself can contain otherSUBQUERY
s)Example:
这是子查询的计算结果。(来自 此邮件列表线程,Google 中“NSPredicate 子查询”的排名第一的点击率。)那段文档还解释了谓词格式字符串语法如何与其相关。
This is what a subquery evaluates to. (Found from this mailing list thread, the #1 hit for “NSPredicate subquery” in Google.) That bit of documentation also explains how the predicate format string syntax relates to it.
子查询表示一个谓词(第三个参数 -
$x IN %@
),该谓词对所有对象(第二个参数 -$x
- 它就像 foreach 中的变量名)进行计算关系(第一个参数 -Bs
)。与常规查询类似,返回对象列表。我在很多地方看到人们几乎教条地使用
$x
,但是objects
关系中的$object
也非常有意义(或者
...) :)cities
中的 $city我前段时间写了一篇关于
SUBQUERY
的博客文章。您可以在此处查看。Subquery represents a predicate (third argument -
$x IN %@
) that is evaluated on all objects (second argument -$x
- it's like a variable name in foreach) of a relationship (first argument -Bs
). Similarly to regular query returns a list of objects.I see in many places that people use
$x
almost dogmatically, but$object
inobjects
relationship makes perfect sense as well (or$city
incities
...) :)I've written a blog post about
SUBQUERY
some time ago. You can check it here.