How to quickly add Core Data to an app in Xcode 4
This is a quick tutorial for adding Core Data to your existing project when you forgot to click the Core Data check box at the start. It's is a re-print of the self created tutorial I use each time. If you have any problems please drop me a mail.
Add the 3x @property definitions to the app delegate header (.h)
Add the 2x method definitions to the app delegate header (.h)
Add the CoreData.framework to your app’s target.
In the "YourApp-Prefix.pch" add the following to the existing statement block
Found in the "Supporting Files" group tree:
Add the 3x @synthesize properties to the app delegate implementation.
Add the 2+3x method implementations to the app delegates implementation (.m)
Change the line that says AppWithCoreData ... momd so the text AppWithCoreData is the name of the xcdatamodeld file you will create next, minus the .xcdatamodeld bit.
You should be able to compile at this point.
Right click in the applications group tree to add a "New File" to the application.
Select iOS > CoreData in the left hand menu and then the "Data Model" icon to add it to the new project.
Click the MyModel.xcdatamodeld and at the bottom of the center pane click "Add Entity"; this has an icon of a plus sign.
Add attributes of the entity in the center panel
There you have it! Core Data is now part of your application.
You can test Core Data works by using this snippet in the App delegate's application did finish launching method:
For a tutorial in using the Core Data Api check the Apple developer documentation.