iphonemaclover iphonemaclover - 1 year ago 111
Objective-C Question

Fix NSPredicate

NOTE: employeename is a key in an array of multiply key value pair

NSPredicate to find result of all employee name when user type character wise search

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"employeename BEGINSWITH[cd] %@", searchtxtField.text];
NSArray *elementFound= [arr_employeeData filteredArrayUsingPredicate:predicate];

employeename = "Anoop";
employeeMobile = 11111111;
employeename = "Anoop singh";
employeeMobile = 11111111;
employeename = "Anoop kumar";
employeeMobile = 1133111111;
employeename = "Vijay kumar";
employeeMobile = 22222;


If your type A in search bar he will have to get all results employee name start with A and so on

Answer Source

I guess with your predicate is all Ok. But the result of filtered users will be in

NSArray *elementFound .

Just print it,and use it next in your program. Because this method return filtered array by predicate, but not change the original one. To change original one,

    NSMutableArray * mutab = [[NSMutableArray alloc] initWithArray:arr_employeeData];
    [mutab filterUsingPredicate:predicate];

And "mutab" array, will have filtered results

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download