Pro Core Data for iOS: Data Access and Persistence Engine for iPhone, iPad, and iPod touch Second Edition by Michael Privat Robert Warner

Pro Core Data for iOS: Data Access and Persistence Engine for iPhone, iPad, and iPod touch Second Edition by Michael Privat Robert Warner

Author:Michael Privat, Robert Warner
Language: eng
Format: epub
Publisher: Apress®
Published: 2011-11-20T16:00:00+00:00


Building the Test Application

You can get data out of a Core Data persistent store in two ways. If you already have handles to existing managed objects, then you can follow the object graph and relationships to pull more objects out. If you don't have any objects yet, such as when the application first starts, then you must go get them directly out of the persistent store. In this case, you typically use an instance of NSFetchRequest to go get objects. You initialize an NSFetchRequest with an NSEntityDescription, which helps narrow the result set by constraining the type of managed objects to retrieve. This chapter shows you how to narrow your fetch requests in various ways using the NSFetchRequest class.

To support the examples in this chapter, you'll reuse the OrgChart application from Chapter 2. We suggest you make a copy of the application because you will make some changes to Chapter 2's data model in this chapter. Since Chapter 2, you've learned that Core Data can better deal with managing the object graph if all the relationships have an inverse, so go back to the OrgChart application and add reverse relationships for leader and employees. To accomplish this, open the OrgChart.xcdatamodeld data model, and select the Person entity. Since Organization already has the leader relationship to the Person entity, add a relationship called organization in Person, set the destination to Organization, and select leader as the inverse relationship. Person also has a self-referencing relationship called employees, so create a relationship from Person to Person, call it manager, and select employees as the inverse relationship. Also, rename the id attribute of Person to age. Your Person entity should look like Figure 6–1.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.