0

What I'm wanting to do is combine two or queries with an and query

WHERE (id contains[cd] %@ OR name contains[cd] %@) AND manu = %@"

So far I have it working with one of the ors and the and, but I can't figure out how to do both

let predicate1 = NSPredicate(format: "id contains[cd] %@", searchedText)
let predicate2 = NSPredicate(format: "threadManu = %@", manu)
predicate = NSCompoundPredicate.init(type: .and, subpredicates: [predicate1,predicate2])
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ceri Turner
  • 830
  • 2
  • 12
  • 36

1 Answers1

5

You need two NSCompoundPredicate.

let predicate1 = NSPredicate(format: "id contains[cd] %@", searchedText)
let predicate2 = NSPredicate(format: "name contains[cd] %@", searchedText)
let predicate3 = NSPredicate(format: "threadManu = %@", manu)

let predicateOr = NSCompoundPredicate(type: .or, subpredicates: [predicate1, predicate2])
let predicate = NSCompoundPredicate(type: .and, subpredicates: [predicateOr, predicate3])
rmaddy
  • 314,917
  • 42
  • 532
  • 579