I am developing iOS app, in which i have searchBar.
What i want is,
when user types s
in the searchBar, i want to get all the Merchant_Name
who starting with letter s
from my array
Here is my code snippet i have tried but it is not working,
My arr contains:
arr at index 0 = {
"Merchant_Id" = 1261;
"Merchant_Name" = "Magazine Mall";
"Merchant_Url" = "magazine-mall";
},
arr at index 1 = {
"Merchant_Id" = 1262;
"Merchant_Name" = MakeMyTrip;
"Merchant_Url" = makemytrip;
},
arr at index 2 = {
"Merchant_Id" = 1263;
"Merchant_Name" = Travelguru;
"Merchant_Url" = travelguru;
},
arr at index 3 = {
"Merchant_Id" = 1266;
"Merchant_Name" = Travelchacha;
"Merchant_Url" = travelchacha;
},
arr at index 4 = {
"Merchant_Id" = 1267;
"Merchant_Name" = Tradus;
"Merchant_Url" = tradus;
},
arr at index 5 = {
"Merchant_Id" = 1268;
"Merchant_Name" = ToyWorld;
"Merchant_Url" = toyworld;
},
arr at index 6 = {
"Merchant_Id" = 1269;
"Merchant_Name" = Topskin;
"Merchant_Url" = topskin;
},
....
Code:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Merchant_Name LIKE[cd] %@ ",searchText];
NSMutableArray *filter1 =[[NSMutableArray alloc] init];
filter1 = [[arr filteredArrayUsingPredicate:predicate] mutableCopy];
NSLog(@"predicate = %@ ------- filter=%@",predicate,filter1);
Log Shows:
predicate = Merchant_Name LIKE[cd] "s" ------- filter=(
)
Please help me, Where i am doing mistake?
Thanks in advance.