Searching a dictionary in an array using a predicate

I have a set of dictionaries and I want to find a dictionary with the correct value for the "guid" key. Can't get this code:

NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid = %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];

      

+3


source to share


6 answers


Try it.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Name CONTAINS[cd] %@",searchBar.text];

filterdArray = [[hospitalArray filteredArrayUsingPredicate:predicate] mutableCopy];

      



Where Name

is the key contained in the dictionary under the array.

+5


source


I think you forgot the "=" sign.



 NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
 NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];

      

+1


source


The operator's state was forgotten;)

You need to add a double "=" like this:

NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];

      

Hope this helps you!

0


source


NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(guid CONTAINS[c] %@)",key];
NSArray *array = [[NSArray arrayWithArray:sampleArray] filteredArrayUsingPredicate: predicate];

      

in the above code, "fromDate" is the dictionary key.

Hope this works for you.

0


source


You can try to initiate NSPredicate like:

NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"guid = '%@'", key]];

      

Hope it helps.

0


source


Try it,

NSArray *filtered = [array_with_dict filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(guid == %@)", @"desired value"]];

      

0


source







All Articles