一个

时间:2018-03-13 18:39:49

标签: swift nspredicate

我想要做的是将两个或查询与一个和查询结合起来

WHERE(id包含[cd]%@ OR名称包含[cd]%@)AND manu =%@"

到目前为止,我已经与其中一个和o一起工作了,但是我无法弄清楚如何做到这两个

let predicate1 = NSPredicate(format: "id contains[cd] %@", searchedText)
let predicate2 = NSPredicate(format: "threadManu = %@", manu)
predicate = NSCompoundPredicate.init(type: .and, subpredicates: [predicate1,predicate2])

1 个答案:

答案 0 :(得分:3)

您需要两个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])