gpt4 book ai didi

Swift 谓词 AND 和 OR 合二为一

转载 作者:行者123 更新时间:2023-11-28 10:44:00 29 4
gpt4 key购买 nike

我想做的是将两个 or 查询与一个 and 查询结合起来

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

到目前为止,我可以使用 or 和 and 之一,但我无法弄清楚如何同时执行这两个操作

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

最佳答案

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

关于Swift 谓词 AND 和 OR 合二为一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49263581/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com