When ever user search for anything like name , phone number , url, email addres then I want to search that query against address book data. My solution is working fine but it is slow . If address book data is huge , app gets stuck. How can I optimize the search , so that my application won’t hang even in large address book data?
EDIT 1 Here is my code
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[self takeSomeActionWhenTextChange];
}
-(void)takeSomeActionWhenTextChange{
[contactArray removeAllObjects];
NSString *searchText=[[textSearchBar text] lowercaseString];
for (int index=0; index<count; index++) {
ABRecordRef record=CFArrayGetValueAtIndex(people, index);
//[self checkStringISAddress:searchText withRecord:record];
if ([self checkStringIsFirstName:searchText withRecord:record]==YES
|| [self checkStringIsLastName:searchText withRecord:record] == YES
||[self checkStringIsNote:searchText withRecord:record]==YES
|| [self checkStringIsAddress:searchText withRecord:record]==YES
|| [self checkStringIsCompany:searchText withRecord:record]==YES
||[self checkStringIsEmail:searchText withRecord:record]
||[self checkStringIsPhonenumber:searchText withRecord:record]==YES )
{
NSLog(@"object added inside Array");
[contactArray addObject:record];
[contactTableView reloadData];
}else{
NSLog(@"No Match For this object");
[contactTableView reloadData];
}
}
}
I will check if substring from search query matches with first name, last name , email & so on. Above methods contain logic to check if substring is present or not? If ti matches , i will add it to array else not.
SHOULD I USE THREAD OR GCD TO PERFOEM SEARCH ? IF YES , HOW? HOW CAN I UPDATE MY TABLE VIEW?
I have one that maybe help you
1.Get all contacts
2.Create another array(records) from the contacts array(thePeoples)
3.Search the mutableArray(records) with predicate
Hope it’ll help you