Reputation: 33
I have an array of dictionaries and I want to find the dictionary with desired value for key "guid". Can not get it with this code:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid = %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
Upvotes: 3
Views: 5086
Reputation: 721
Try this.
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.
Upvotes: 5
Reputation: 40
You could try to initiate the NSPredicate as:
NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"guid = '%@'", key]];
Hope it helps.
Upvotes: 0
Reputation: 1421
Try this,
NSArray *filtered = [array_with_dict filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(guid == %@)", @"desired value"]];
Upvotes: 0
Reputation: 344
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(guid CONTAINS[c] %@)",key];
NSArray *array = [[NSArray arrayWithArray:sampleArray] filteredArrayUsingPredicate: predicate];
in above code "fromDate" is key of dictionary.
i hope this works for you.
Upvotes: 0
Reputation: 4187
The operator condition has been forgotten ;)
You need to add a double "=" like this :
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
I hope this can help you !
Upvotes: 0
Reputation: 2945
I think you forgot "=" sign.
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
Upvotes: 1