从字典数组中搜索值

ios*_*per 2 objective-c nsmutablearray uisearchbar nspredicate

我有NSMutableArray词典:类似于:

(
{
    "Key1" = "Name1";
    "Key2" = "Age1";
    "Key3" = "Address1";
 },
{
    "Key1" = "Name2";
    "Key2" = "Age2";
    "Key3" = "Address2";
},
{
    "Key1" = "Name3";
    "Key2" = "Age3";
    "Key3" = "Address3";
}
)
Run Code Online (Sandbox Code Playgroud)

使用此代码搜索键1值.用户可以键入偶数字母表,我必须使用包含该字母表的键搜索所有字典.

NSPredicate *filter = [NSPredicate predicateWithFormat:@"'Key1' =[cd] %@", searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];
Run Code Online (Sandbox Code Playgroud)

但这个谓词不起作用.请帮忙.

Ron*_*ara 7

尝试使用以下代码检查.

使用contains[c]NSPredicate象下面这样:

NSPredicate *filter = [NSPredicate predicateWithFormat:@"Key1 contains[c] %@ ",searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];
Run Code Online (Sandbox Code Playgroud)