Is there a way to "Invert" NSPredicate

Say I have this predicate:

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

And I want to undo this predicate:

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

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

+4
source share
1 answer

You cannot modify an existing one NSPredicate. But you can easily create a new predicate that is “inverse” (or, more precisely, negation) filter:

NSPredicate *notFilter = [NSCompoundPredicate notPredicateWithSubpredicate:filter];

See the documentation +[NSCompoundPredicate notPredicateWithSubpredicate:].

+7
source

Source: https://habr.com/ru/post/1544116/


All Articles