Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching dictionary in array using predicate

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];
like image 556
avfvadfv fnvadlfjnvadlf Avatar asked Dec 02 '25 07:12

avfvadfv fnvadlfjnvadlf


2 Answers

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.

like image 107
yogesh wadhwa Avatar answered Dec 03 '25 21:12

yogesh wadhwa


I think you forgot "=" sign.

 NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
 NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
like image 45
Pratik Mistry Avatar answered Dec 03 '25 19:12

Pratik Mistry



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!