Adding Core Data to existing iPhone project

All the CoreData header files are imported in App_Prefix.pch, so the CoreData classes will be available throughout your Project, so you don’t have to manually import the header in the files you need them.

So open up Xcode and look for some file like App_Prefix.pch, by default it’s in the Other Sources group. After the UIKit import statement, add the following line:

#import <CoreData/CoreData.h>

And you should be ready to go.

Xcode 4

For projects created in Xcode 4, the prefix file can be found in the Supporting Files group in the Project navigator. It’s called ‘projectname-Prefix.pch’ by default.

Xcode 6+

Starting with Xcode 6, the precompiled header file is no longer included by default. This is because of the introduction of Modules, which take away the need to use precompiled headers. While it is still possible to manually add a PCH file to globally include the CoreData headers, consider specifying the CoreData dependency using @import CoreData;* in every file that uses CoreData. This makes dependencies explicit and more importantly will avoid this question’s problem in the future.

* Modules need to be enabled for this to work.

Leave a Comment