James Sun
James Sun

Reputation: 1461

"Use Core Data for storage" checkbox

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!

Upvotes: 6

Views: 4367

Answers (1)

Alex Reynolds
Alex Reynolds

Reputation: 96967

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, which should be findable from the Apple Developer Center website via its search engine, or via your favorite search engine. I will not add links here, so as not to cause offense.

Upvotes: 8

Related Questions