Fetch Request Filtering

When it isn’t appropriate to fetch everything possible for an entity, you can filter fetches using a predicate. A predicate is defined for a fetch request using an instance of NSPredicate and then passing it to an instance of NSFetchRequest. Using a predicate will limit the number of managed objects returned in the fetched results based on the criteria specified. Predicates are persistent store agnostic, so you can use the same predicates regardless of the backend store. That said, there are some corner cases where particular predicates won’t work with certain stores. For example, the matches operator works with in-memory filtering; however, it does not with an SQLite store. In SQL database terms, a predicate is similar ...

Get Learning Core Data for iOS: A Hands-On Guide to Building Core Data Applications 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.