Recipe: Search Tables and Core Data
Core Data stores are designed to work efficiently with NSPredicate
s. Predicates allow you to create fetch requests that select only managed objects that match the predicate’s rule or rules. Adding a predicate to a fetch request limits the fetched results to matching objects. Recipe 12-2 takes advantage of the predicates introduced earlier in this chapter to add searching to a table view.
Users may search for entries whose last names match the search string they type. As the text in the search bar at the top of the table changes, the search bar’s delegate receives a searchBar:textDidChange:
callback. In turn, that callback method performs a new fetch, using that string as the basis for searching.
Only a few ...
Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.