gpt4 book ai didi

ios - 搜索过滤器必须从 [[String : Any]]() array to new filtered array?

转载 作者:行者123 更新时间:2023-11-29 05:45:27 25 4
gpt4 key购买 nike

我有一个 tableview ,我正在其中加载我命名为 PlaylistArray 的数组中的所有详细信息。我有一个搜索页面,用户可以从 [[String: Any]] 类型的 playlistArray 中搜索。我不知道如何将 PlayListArray 中用户给出的搜索文本过滤为 filteredArray。我已附上 PlaylistArray 响应供您引用。

这是我之前尝试过的用于过滤PlaylistArray的代码。

 let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text!)
let array = (constantsList.playTypeArray.lectureArraymp3 as NSArray).filtered(using: searchPredicate)
// filtered_Array.add(array)
print(array)

我需要搜索用户提供的搜索文本,并且我们必须将搜索文本与 playlistArraytitle 标签进行比较。当两者相同时,我需要向过滤数组显示特定数组索引的完整详细信息。

播放列表数组:

[["title": Kaṭha-Bhāṣyam-41 Mantra 1-2-20, "image_url": https://www.imaginetventures.name/swamijione/wp-content/uploads/2019/01/gitanew.png, "mp3": https://www.imaginetventures.name/swamiji/wp-content/uploads/2018/12/01-PURU],["title": Kaṭha-Bhāṣyam-41 Mantra 1-2-20, "image_url": https://www.imaginetventures.name/swamijione/wp-content/uploads/2019/01/gitanew.png, "mp3": https://www.imaginetventures.name/swamiji/wp-content/uploads/2018/12/01-PURU],["title": Kaṭha-Bhāṣyam-41 Mantra 1-2-20, "image_url": https://www.imaginetventures.name/swamijione/wp-content/uploads/2019/01/gitanew.png, "mp3": https://www.imaginetventures.name/swamiji/wp-content/uploads/2018/12/01-PURU]]

最佳答案

这是一个使用 filter API 的 swift 解决方案。在这里阅读更多相关信息:https://developer.apple.com/documentation/swift/sequence/3018365-filter

let array = [["title": "Kaṭha-Bhāṣyam-41 Mantra 1-2-20", "image_url": "https://www.imaginetventures.name/swamijione/wp-content/uploads/2019/01/gitanew.png"],
["title": "Kaṭa-Bhāṣyam-41 Mantra 1-2-20", "image_url": "https://www.imaginetventures.name/swamijione/wp-content/uploads/2019/01/gitanew.png"]]

guard let searchText = searchController.searchBar.text else {return} //Or use if-let
let filteredArray = array.filter { (object) -> Bool in
guard let title = object["title"] as? String else {return false}
return title?.contains(searchText) ?? false
}

关于ios - 搜索过滤器必须从 [[String : Any]]() array to new filtered array?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56186936/

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