As far as I know there is no spotlight API for the iPhone.
You don't need one. Here's one way to go about it:
- Put your contacts into a Core Data persistent store
- Use
NSFetchedResultsController
to manage a result set
- Use
UISearchDisplayController
to apply an NSPredicate
on the result set in real time
The only threading I can see that you would need is a separate thread to populate the Core Data store with contacts.
Once you have a result set via NSFetchedResultsController
, it is quite easy to apply a predicate. For example:
if ([self.searchBar.text length]) {
_predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"(myContactName contains[cd] '%@')", self.searchBar.text]];
[self.fetchedResultsController.fetchRequest setPredicate:_predicate];
}
NSError *error;
if (![self.fetchedResultsController performFetch:&error]) {
// handle error...
}
NSLog(@"filtered results: %@", [self.fetchedResultsController fetchedObjects]);
will filter the result set [self.fetchedResultsController fetchedObjects]
on the fly.