Fetching and Sorting Objects

To work with existing managed objects, they need to be fetched from the managed object context. There are two methods to fetch managed objects: directly using the objectID, or by constructing a fetch request.

Core Data gives each managed object a unique ID, which is an instance of NSManagedObjectID, called objectID. If that objectID has been stored for an object, it can be used to fetch the object:

NSManagedObject *myObject = [kAppDelegate.managedObjectContext                          objectWithID:myObjectID];

The objectWithID method will return nil if an object with myObjectID is not found, or will return one NSManagedObject if it is found.

To fetch managed objects by specifying attribute ...

Get iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK 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.