gpt4 book ai didi

ios - 使用谓词 iOS SDK 从字典数组中过滤数据

转载 作者:可可西里 更新时间:2023-11-01 04:04:45 24 4
gpt4 key购买 nike

大家好,我有一个字典数组,你们能告诉我如何根据字典键过滤这些数据吗?

(
{
"mall_id" = M0550;
"mall_name" = "Amrita Shopping Complex";
},
{
"mall_id" = M0509;
"mall_name" = "Ashoka Market";
},
{
"mall_id" = M0943;
"mall_name" = "Biju Pattnaik Commercial Complex";
},
{
"mall_id" = M0457;
"mall_name" = "BMC Bhawani Mall";
},
{
"mall_id" = M0460;
"mall_name" = "BMC Keshari Mall";
},
{
"mall_id" = M0571;
"mall_name" = "BMC Market Complex";
},
{
"mall_id" = M0453;
"mall_name" = "Forum Mart";
},
{
"mall_id" = M0609;
"mall_name" = "Indradhanu Market";
},
{
"mall_id" = M0558;
"mall_name" = "Kalyani Plaza Market Complex";
},
{
"mall_id" = M0463;
"mall_name" = "Maa Barabhuja Mall";
},
{
"mall_id" = M0553;
"mall_name" = "Mahaveer Complex";
},
{
"mall_id" = M0570;
"mall_name" = "Market Building";
},
{
"mall_id" = M0452;
"mall_name" = "Pal Heights Mall";
},
{
"mall_id" = M0466;
"mall_name" = "Priyadarshini Market Complex";
},
{
"mall_id" = M0677;
"mall_name" = "Ruchika Market";
},
{
"mall_id" = M0504;
"mall_name" = "Shubham Market Complex";
},
{
"mall_id" = M0564;
"mall_name" = "Subhadra Complex";
},
{
"mall_id" = M0559;
"mall_name" = "Sultania Shopping Complex";
},
{
"mall_id" = M0552;
"mall_name" = "Tathastu Complex";
},
{
"mall_id" = M0568;
"mall_name" = "Western Tower Market Building";
}
)

我想要实现的目标是,每当我在搜索栏中键入任何内容时,它都会检查 mall_name 键并返回数组中的匹配值。

感谢和问候

最佳答案

这将为您提供所需的输出

目标 - C

NSArray *filteredData = [yourArrayContainingDictionary filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(mall_name contains[c] %@)", searchText]];

swift

let filteredData = yourArrayContainingDictionary.filter{
let string = $0["mall_name"] as! String

return string.hasPrefix("searchText")
}

希望这对你有帮助:)

关于ios - 使用谓词 iOS SDK 从字典数组中过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45026796/

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