本文介绍了使用谓词iOS SDK从Dictionary数组过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我有一个字典数组,你们能告诉我如何根据字典键过滤此数据吗?
Hello guys i have an array of dictionary, can you guys tell me how can i filter this data based on dictionary keys.
(
{
"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键并在数组中返回匹配的值.
what i want to achieve, whenever i type anything in search bar it will check mall_name key and return matching values in array.
感谢和问候
推荐答案
这将为您提供所需的输出
This will give you your desired output
目标-C
NSArray *filteredData = [yourArrayContainingDictionary filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(mall_name contains[c] %@)", searchText]];
快速
let filteredData = yourArrayContainingDictionary.filter{
let string = $0["mall_name"] as! String
return string.hasPrefix("searchText")
}
希望这对您有所帮助:)
Hope this helps you :)
这篇关于使用谓词iOS SDK从Dictionary数组过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!