gpt4 book ai didi

ios - NSPredicate 与字符串完全匹配

转载 作者:搜寻专家 更新时间:2023-11-01 07:24:41 25 4
gpt4 key购买 nike

你好,我正在研究 swift。我需要知道如何找到与确切字符串匹配的结果。这是我的代码

let userID: String = String(sender.tag)
// Create a Predicate with mapping to trip_id
let filterByRequest: NSPredicate = NSPredicate(format: "%K.%K CONTAINS[c] %@", "ProductRequest", "user_id", userID)
// Filter your main array with predicate, resulting array will have filtered objects
let filteredArray: [AnyObject] = self.array.filteredArrayUsingPredicate(filterByRequest)

问题是如果用户 ID 是 69,它会显示 ID 为 69、6 和 9 的用户的结果。

我用谷歌搜索,但我找到了一些与我的问题相关的答案,但它们都在 objective-c 中。

最佳答案

在谓词中使用 MATCHES 如下:

let filterByRequest: NSPredicate = NSPredicate(format: "%K.%K MATCHES %@", "ProductRequest", "user_id", userID)

希望对你有帮助..

关于ios - NSPredicate 与字符串完全匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36883329/

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