how do I use compound predicates

I want to make a fetchRequest.predicate which checks for both


NSPredicate(format:"commited == %@", "commited") and

NSPredicate(format:"commited == %@", "sold")


Checking the documentation I found compound predicates but I have been unable to get them to compile without errors. Is there a way to do this in Swift3 for IOS 10?


Thanks


Russ

Accepted Answer

Have you tried the straight forward version?


Combine the predicates "commited == %@" and "commedit == %@" into


NSPredicate(format: "(commited == %@) || (commited == %@)", "commited", "sold")

?


Sure, technically the various NSPredicate subclasses exist, but it's a lot easier to just use NSPredicate:format: on the compound expression.


Otherwise, what have you been trying for the expression to invoke NSCompoundPredicate(orPredicateWithSubPredicates: <array>), and what error messages have you received?

Thanks


All I had to change was the || to && and it solved my problem.

how do I use compound predicates
 
 
Q