Reputation: 3616
I am working on app where i would like to show a tableview with 10k+ I am using fetchedresultcontroller from cs193p and it works well. Loads up and scroll is pretty quick. I would like to be able to search with each letter.
I setup search bar and delegates and have the searchbar textdidchange method reload fetchresults controller with each letter. It works but with delays is there anyway to make it faster.
This is my textdidchange method
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
//NSLog(@"%@",searchText);
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"People"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"fullname" ascending:YES]];
[NSFetchedResultsController deleteCacheWithName:@"peopleCache"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstname contains[c] %@)",searchText];
request.predicate = predicate;
self.fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:request managedObjectContext:self.peopleDatabase.managedObjectContext sectionNameKeyPath:nil cacheName:@"actorCache"];
}
Is there any way to filter the existing query without actually refetching the data?
Any suggestions will be greatly appreciated!
Upvotes: 1
Views: 543
Reputation: 14539
you can search through an existing array with a predicate, but it will probably fault in all of the fields that you are searching through... which depending on the application could be a bad thing (i.e. slower and more memory used that just refetching).
Upvotes: 0
Reputation: 3463
Tricks for optimizing textual search are mentioned in the "Optimizing Core Data Performance on iPhone OS" WWDC session.
Upvotes: 1