I started off the project without Core Data and now I would like to add that functionality to my apps. How do I do this?
What additional things does XCode sets up when you actually tick the Use Core Data when you create a new project?
Get our help adding Core Data to your project So, with your existing project open, create a new project in Xcode (⇧⌘N) and select a Single View App, you can call it whatever you like as we'll be deleting it when we're done. You'll see the “Use Core Data” checkbox on the project options screen, make sure it is checked.
Add a Core Data Model to an Existing Project Choose File > New > File and select the iOS platform tab. Scroll down to the Core Data section, select Data Model, and click Next. Name your model file, select its group and targets, and click Create.
One trick is to just create a new empty project with Core Data support. That will give you the necessary code that you can copy over to your original project and compile.
The only gotcha is that you need to handle the Core Data header file. Xcode puts it in the precompiled header files when it generates files using the templates. So you can add the following line to your .pch file:
#import <CoreData/CoreData.h>
or you can just add it to the .m files where needed.
It works like a charm. Notice Luka's comment below about how to do it in Xcode5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With