Adding master data to the existing project in XCode 4


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?

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.