cfischer - 1 month ago 6
Objective-C Question

# Difference between ALL , ANY and SOME operators in NSPredicate

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`
.

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

ALL members.age > 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.

ANY members.age > 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)
``````

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.