試試這個。
NSString *str=[NSString stringWithFormat:@"FullName beginswith[c] '%@' OR FirstName beginswith[c] '%@' OR LastName beginswith[c]'%@'",searchString,searchString,searchString];
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:str];
arraySearchResult = [arrayConatcts filteredArrayUsingPredicate:bPredicate];
// allocate an empty mutable array in which to accumulate the matches
NSString *str1=[NSString stringWithFormat:@"self beginswith[c]'%@'",searchString];
NSPredicate *Predicate = [NSPredicate predicateWithFormat: str1];
NSMutableArray *test = [NSMutableArray new];
for(FreindsContact *obj in arrayConatcts)
{// loop over each sub array
NSMutableArray *filtered = [NSMutableArray new];
[filtered addObjectsFromArray:[obj.ContactNoArray filteredArrayUsingPredicate: Predicate]];
if (filtered.count>0)
{
[test addObject:obj];
}else
{
[filtered addObjectsFromArray:[obj.EmailArray filteredArrayUsingPredicate: Predicate]];
if (filtered.count>0)
{
[test addObject:obj];
}
}
}
DLog(@"%@",test);
for (FreindsContact *obj in arraySearchResult)
{
if ([test containsObject:obj])
{
[test removeObject:obj];
}
}
if (test.count>0) {
arraySearchResult=test;
}