user1960169
user1960169

Reputation: 3663

How to search something on NSMutableArray using predicate

I have a NSMutableArray it has several dictionary objects like this.

"DisplayName": "ART42 - Jomon Williams", 
    "DisplayName2": "Jomon Williams", 
    "EmployeeNumber": "ART42", 
    "Designation": "Senior Executive - Systems", 

I have a UITextField when its text changing I want to reload my UITableView with search filtered array. For Searching I did something like this. When my text is changing im doing this.

    NSPredicate *exists = [NSPredicate predicateWithFormat:@"SELF CONTAINS[cd] %@", searchText];
    NSLog(@"Predicate-------%@",exists);

    NSArray *aList = [mutArrayStaff filteredArrayUsingPredicate:exists];

I want to search by DisplayName2key. Everytime my aList array is empty. How can I write my predicate correctly inorder to search on DisplayName2

Please help me. Thanks

Upvotes: 2

Views: 407

Answers (1)

Ozgur Vatansever
Ozgur Vatansever

Reputation: 52223

Assuming the mutArrayStaff is a list of dictionaries, each of them containing DisplayName2 as the key, you can do the following:

NSPredicate *exists = [NSPredicate predicateWithFormat:@"(DisplayName2 CONTAINS[cd] %@)", searchText];

Upvotes: 3

Related Questions