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
avfvadfv fnvadlfjnvadlf
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
yogesh wadhwa
source
to share
I think you forgot the "=" sign.
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
+1
Pratik mistry
source
to share
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
thedjnivek
source
to share
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
Urmi
source
to share
You can try to initiate NSPredicate like:
NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"guid = '%@'", key]];
Hope it helps.
0
Javito_009
source
to share
Try it,
NSArray *filtered = [array_with_dict filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(guid == %@)", @"desired value"]];
0
utkal patel
source
to share