0

I have an NSManagedObject SchoolClass that has a To Many relationship to Students. I have it working for when I want to find SchoolClasses containing a specified student by using,

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"(ANY students == %@)", student];

How would I set up an NSPredicate to return an NSArray of SchoolClasses that do NOT contain a specified student? I thought something like below would work but it does not.

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"(NONE students IN %@)", student];
4

1 回答 1

1

IN is used when the right-hand side is a collection, such as an array of students. Try this predicate instead:

[NSPredicate predicateWithFormat:@"(NONE students = %@)", student];

This is also equivalent to ALL students != %@.

This will only return SchoolClasses who do not include the specified student.

于 2013-11-04T22:40:02.973 回答