Database Reference
In-Depth Information
Fetching different result types
All this time, you've probably been thinking of NSFetchRequest as a fairly simple
tool. You give it some instructions and you get some objects in return. What else is
there to it?
If this is the case, you've been underestimating this class. NSFetchRequest is the
multi-function Swiss army knife of the Core Data framework! You can use it to fetch
individual values, compute statistics on your data such as the average, minimum
and maximum, and more.
How is this possible, you ask? NSFetchRequest has a property named resultType . So
far, you've only used the default value, NSManagedObjectResultType . Here are all the
possible values for a fetch request's result type:
NSManagedObjectResultType: Returns managed objects (default value).
NSCountResultType : Returns the count of the objects that match the fetch
request.
NSDictionaryResultType : This is a catch-all return type for returning the results
of different calculations.
NSManagedObjectIDResultType : Returns unique identifiers instead of full-
fledged managed objects.
Let's go back to the sample project and apply these concepts in practice.
With the sample project running, tap Filter in the top-right corner to bring up the
UI for the filter screen. You won't implement the actual filters/sorts right now.
Instead, you'll focus on the following four labels:
 
 
Search WWH ::




Custom Search