gpt4 book ai didi

ios - 快速 NSPredicate 逻辑或

转载 作者:行者123 更新时间:2023-11-28 05:33:23 24 4
gpt4 key购买 nike

我有一个单一的字符串替换与 NSPredicate 一起工作,但返回包含 StringA 或 StringB 的核心数据记录似乎不是我能弄清楚的。我想要这样的东西:

let filter = NSPredicate(format: ("%K = %@", "type", "StringA") OR ("%K = %@", "type", "StringB"))

但这当然行不通。帮助?

最佳答案

你必须指定一个格式字符串,后跟以逗号分隔的参数列表以替换为以下格式:

let filter = NSPredicate(format:"%K = %@ OR %K = %@", "type", "StringA", "type", "StringB")

如果键不是保留字且不包含特殊字符,那么您可以直接在格式字符串中指定它们:

let filter = NSPredicate(format:"type = %@ OR type = %@", "StringA", "StringB")

关于ios - 快速 NSPredicate 逻辑或,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26480292/

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