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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With