从字典数组中搜索值
search value from array of dictionary
我有 NSMutableArray
部词典:
类似于:
(
{
"Key1" = "Name1";
"Key2" = "Age1";
"Key3" = "Address1";
},
{
"Key1" = "Name2";
"Key2" = "Age2";
"Key3" = "Address2";
},
{
"Key1" = "Name3";
"Key2" = "Age3";
"Key3" = "Address3";
}
)
使用此代码搜索键 1 值。
用户甚至可以键入字母表,我必须使用包含该字母表的键搜索所有字典。
NSPredicate *filter = [NSPredicate predicateWithFormat:@"'Key1' =[cd] %@", searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];
但是这个谓词不起作用。请帮忙
尝试使用以下代码进行检查。
在 NSPredicate
中使用 contains[c]
,如下所示:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"Key1 contains[c] %@ ",searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];
我有 NSMutableArray
部词典:
类似于:
(
{
"Key1" = "Name1";
"Key2" = "Age1";
"Key3" = "Address1";
},
{
"Key1" = "Name2";
"Key2" = "Age2";
"Key3" = "Address2";
},
{
"Key1" = "Name3";
"Key2" = "Age3";
"Key3" = "Address3";
}
)
使用此代码搜索键 1 值。 用户甚至可以键入字母表,我必须使用包含该字母表的键搜索所有字典。
NSPredicate *filter = [NSPredicate predicateWithFormat:@"'Key1' =[cd] %@", searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];
但是这个谓词不起作用。请帮忙
尝试使用以下代码进行检查。
在 NSPredicate
中使用 contains[c]
,如下所示:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"Key1 contains[c] %@ ",searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];