NSPredicate中ALL,ANY和SOME运算符之间的区别 [英] Difference between ALL , ANY and SOME operators in NSPredicate

查看:173
本文介绍了NSPredicate中ALL,ANY和SOME运算符之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很难理解这3个。看起来 ANY SOME 都做同样的事情,但我看不到 ALL 有什么区别。

I'm really struggling to understand these 3. It looks like ANY and SOME do the same thing, but I don't see the difference with ALL.

推荐答案

有一个组列表。每个组都有类型为person的成员。每个人都有年龄。

Let's have a list of groups. Every group has members of type person. Every person has an age.

所有会员。年龄> 30

ALL members.age > 30

意味着您将找到一个与成员都超过30岁。您将找不到一个至少有一个成员不超过30岁的小组。

means that you will find a group with members that are all older than 30. You will not find a group with at least one single member being 30 or younger.

任何member.age> 30

ANY members.age > 30

表示您将找到一个至少有一个成员年龄大于30岁的组。您将找不到一个所有成员都不超过30岁的组。

means that you will find a group with at least one member older than 30. You will not find a group with all members being 30 or younger.

Group1      > 30
  Amin  45  YES
  Chris 29  NO
            ---
All         NO  (because Chris is too young)
Any         YES (because Amin is old enough)

Group2      > 30
  Amin  45  YES
  Foo   35  YES
            ---
All         YES (because all members are old enough)
Any         YES (because at least one member is old enough)


Group3      > 30
  Chris 29  NO
  Bar   21  NO
            ---
All         NO  (because at least one member is too young)
Any         NO  (because all members are too young)

使用ALL谓词,您会找到Group2,因为所有成员(Amin,Foo)都与该谓词匹配。使用ANY谓词,您将找到两个组,因为在这两个组中,至少有一个成员匹配该谓词。

With the ALL predicate you find Group2, because all members (Amin, Foo) matches the predicate. With the ANY predicate you will find both groups, because in both groups at least one member matches the predicate.

这篇关于NSPredicate中ALL,ANY和SOME运算符之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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