my current array looks like below. i create this array format for sectionIndex table. so i can search from array and display search text using index table.
arrContent = (
{
key = A;
value = (
Ac,
Acting
);
},
{
key = B;
value = (
Basketball,
Baseball
);
},
{
key = C;
value = (
Cat
);
}
{
key = P;
value = (
Panda,
Peacock
);
}
)
My Search code looks like below. and it is working fine.
-(void)searchText:(NSString *) text
{
[arrSearch removeAllObjects];
for (int i = 0; i < [arrContent count]; i++)
{
NSMutableArray *temp = [[NSMutableArray alloc]init];
NSMutableArray *arrFind = arrContent[i][@"value"];
for (int j = 0; j < [arrFind count]; j++)
{
NSString *str = arrFind[j];
// containsString: method find my string if its available within range
if ([str containsString:text])
[temp addObject:str];
}
if ([temp count])
{
[arrSearch addObject:@{@"key":arrContent[i][@"key"],@"value":temp}];
}
}
NSLog(@"Search : %@",text);
NSLog(@"arrSearch : %@",arrSearch);
}
i got output like below. which is correct.
Search : ac
arrSearch : (
{
key = A;
value = (
Ac,
Acting
);
},
{
key = P;
value = (
Peacock
);
}
)
I just want to ask that if is there any better way to search and get same output using NSPredicate because for loop will take time when lots of data.
Help would be appriciated.