IPhone Core Data-driven Search: How To, Resources?

I have a very simple Core Data application that pretty much contains lines of text. I would like to make this text searchable and see the “Search and Search Panel Controller” object in Interface Builder.

First, would using the search bar and search display controller be the best approach to simple text search using Core Data? Secondly, could you point me to some resources that would make me start? Perhaps this is a step-by-step guide or sample project - the simpler the better.

I looked at both SO and Apple iPhone Dev Center, but I can not find anything. Thanks again!

+3
source share
1 answer

Here is how I did it. When the delegate

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

tells me that the user typed something in the search bar, I create a predicate

[NSPredicate predicateWithFormat:@"string CONTAINS[c] %@",searchText];

retrieve results from MOC with this predicate, update my result array and report viewing the result table to reload

[[self.searchDisplayController searchResultsTableView] reloadData];

If you have many results, you can try to set a sampling limit and load all results if the user clicks the search button.

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;

Hope this helps.

+3
source

Source: https://habr.com/ru/post/1750098/


All Articles