Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search value from array of dictionary

I have NSMutableArray of dictionaries: something like :

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

Using this code to search key 1 value. User can type even alphabet and I have to search the all the dictionary with key containing that alphabet.

NSPredicate *filter = [NSPredicate predicateWithFormat:@"'Key1' =[cd] %@", searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];

But this predicate is not working. please help.

like image 611
ios developer Avatar asked Mar 13 '26 05:03

ios developer


1 Answers

Try and check using below code.

Use contains[c] in NSPredicate like below:

NSPredicate *filter = [NSPredicate predicateWithFormat:@"Key1 contains[c] %@ ",searchstring];
NSArray *filteredContacts = [DisplayArray filteredArrayUsingPredicate:filter];
like image 197
Ronak Chaniyara Avatar answered Mar 14 '26 22:03

Ronak Chaniyara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!