I have a list of foods (e.g. apple, pear, banana, etc.). Suppose a user type "appl", I want my app to return the top 5 (the number 5 is arbitrary) closest results within this list. What is a good algorithm/data structure for implementing this?
Asked
Active
Viewed 257 times
2 Answers
0
You should get all the data from the database and store it in an array and then if you are using search bar -
(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;
use this method and apply logic to search something like
for(NSString *curString in backUpArayForAllFiles) {
flagCountForSearch++;
if ([curString rangeOfString:substring options:NSCaseInsensitiveSearch].location == NSNotFound)
{
}
else
{
}

Abhinandan Sahgal
- 1,076
- 1
- 13
- 27
0
The usual way is using a UISearchDisplayController to implement the UISearchDisplayDelegate protocol - and use NSPredicate (NSFetchResultsController) to filter through the table(s). I think this may help : NSFetchedResultsController with search