Is there a way of combining predicates in Swift? For example:
let predicate1 = NSPredicate("self.label = 'foo'"))
let predicate2 = NSPredicate("self.label = 'bar'"))
let combinedPredicate = NSPredicate("self.staticTexts.elementMatchingPredicate(%@).exists AND
self.staticTexts.elementMatchingPredicate(%@).exists", predicate1, predicate2)
That gives me an error saying predicates cannot be arguments to other predicates. Is there another way to combine them?
You'll need NSCompoundPredicate
:
let predicate1 = NSPredicate(format: "self.label = 'foo'", argumentArray: [])
let predicate2 = NSPredicate(format: "self.label = 'bar'", argumentArray: [])
let compound = NSCompoundPredicate(andPredicateWithSubpredicates: [predicate1, predicate2])
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