NSPredicate with AND OR and NOT condition

suggest change

Conditional predicate will be cleaner and safer by using the NSCompoundPredicate class which provides basic boolean operators for the given predicates.

Objective-c

AND - Condition

NSPredicate *predicate = [NSPredicate predicateWithFormat:@“samplePredicate”]; NSPredicate *anotherPredicate = [NSPredicate predicateWithFormat:@“anotherPredicate”]; NSPredicate *combinedPredicate = [NSCompoundPredicate andPredicateWithSubpredicates: @[predicate,anotherPredicate]];

OR - Condition

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"samplePredicate"];
 NSPredicate *anotherPredicate = [NSPredicate predicateWithFormat:@"anotherPredicate"];
 NSPredicate *combinedPredicate = [NSCompoundPredicate orPredicateWithSubpredicates: @[predicate,anotherPredicate]];

NOT - Condition

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"samplePredicate"];
 NSPredicate *anotherPredicate = [NSPredicate predicateWithFormat:@"anotherPredicate"];
 NSPredicate *combinedPredicate = [NSCompoundPredicate notPredicateWithSubpredicate: @[predicate,anotherPredicate]];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


NSPredicate:
*NSPredicate with AND OR and NOT condition

Table Of Contents
103NSPredicate
157MVVM