Database Reference
In-Depth Information
Chapter 4: Intermediate
Fetching
By Pietro Rea
In the first three chapters of this topic, you began exploring the foundations of Core
Data, including very basic ways of saving and fetching data to and from your Core
Data persistent store.
For example, you performed simple, unrefined fetches such as “fetch all Bowtie
entities.” Sometimes this is all you need to do, but often you'll want to exert more
control over how you retrieve information from Core Data.
Building on what you've learned so far, this chapter dives deep into the topic of
fetching . Fetching is a large topic in Core Data, and you have many tools at your
disposal. By the end of this chapter, you'll know how to:
fetch only what you need to;
refine your fetched results using predicates;
fetch in the background to avoid blocking the UI; and
avoid unnecessary fetching by updating objects directly in the persistent store.
This chapter is a toolbox sampler: Its aim is to expose you to many of the things
you can do with fetching so that when the time comes, you can use the right tool.
NSFetchRequest: the star of the show
As you've learned in previous chapters, the way to fetch records from Core Data is
to create an instance of NSFetchRequest , configure it as you like it and hand it over
to NSManagedObjectContext to do the heavy lifting for you.
Simple enough, right? There are actually four different ways to get ahold of a fetch
request. Some are more popular than others, but you'll likely encounter all of them
at some point as a Core Data developer.
Before jumping to the starter project for this chapter, let's quickly go over the
different ways to set up a fetch request so you're not caught by surprise. They are
demonstrated below:
 
 
Search WWH ::




Custom Search