O'Reilly logo

Core Data in Swift by Marcus S. Zarra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building an NSFetchRequest

NSFetchRequest is the part of Core Data that causes people to think it’s a database API instead of an object hierarchy. When we want to retrieve objects from Core Data, we normally use an NSFetchRequest to do the retrieval. It’s best to view an NSFetchRequest as a way to retrieve all instances of an entity from the object hierarchy, with the option to filter the results with an NSPredicate. There are two parts to the creation of an NSFetchRequest: setting the entity to be retrieved and optionally defining an NSPredicate to filter the objects that we want retrieved.

Setting the Entity

One thing that we must do as part of every NSFetchRequest is define the entity we want returned from the fetch. We do this by passing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required