Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to "Reverse" an NSPredicate

Let's say that I have this predicate:

NSPredicate *filter = [NSPredicate predicateWithFormat:@"%K == NO", @"someAttribute"];

And I wish to reverse that predicate to :

NSPredicate *filter = [NSPredicate predicateWithFormat:@"%K == YES", @"someAttribute"];

Is there a way to do this without creating a new predicate.

like image 678
shannoga Avatar asked Jun 11 '14 07:06

shannoga


1 Answers

You can't modify an existing NSPredicate. But you can very easily create a new predicate that is the “reverse” (or more precisely, the negation) of filter:

NSPredicate *notFilter = [NSCompoundPredicate notPredicateWithSubpredicate:filter];

See the +[NSCompoundPredicate notPredicateWithSubpredicate:] documentation.

like image 156
rob mayoff Avatar answered Oct 24 '22 08:10

rob mayoff