views:

587

answers:

1

What actually happens behind the scenes when you select the "Use Core Data for storage" option when creating a new Window based project in Xcode? I'm trying to use Core Data in a project that I've already created, and I'm having a hard time figuring out how to include the framework properly in my Xcode project...

Thanks!

+1  A: 

In addition to importing <CoreData/CoreData.h>, there is a template which populates the application delegate implementation with the following methods:

-managedObjectContext
-managedObjectModel
-persistentStoreCoordinator

which initialize the applicaton's managedObjectContext, managedObjectModel and persistentStoreCoordinator members. (The application delegate header is populated with hints to these methods, the associated member variables and their property descriptions.)

The template also adds code to -applicationWillTerminate: which writes changes to the managedObjectContext.

The easiest way to figure out what to add (and, more importantly, why) is to go through the iPhone Core Data tutorial.

Alex Reynolds
Thank you very much for your complete answer. Do you know where the various project templates for Xcode are stored?
James Sun
Search Google on "xcode templates". I think you'll find your answer there.
Alex Reynolds