Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Core Data to 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?

like image 317
adit Avatar asked Jul 25 '11 20:07

adit


People also ask

Can you add Core Data to an existing 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.

How do I add Core Data to an existing project in Swift 4?

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.


1 Answers

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.

like image 187
Monolo Avatar answered Oct 13 '22 01:10

Monolo