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.
详见 http://stackoverflow.com/questions/2032818/adding-core-data-to-existing-iphone-project
PS:之前作为返回函数参数类型的NSManagedObjectContext并没有报错,但是在[[NSManagedObjectContext alloc] init]的时候,却突然报了标题的错误,让我没有联想到头文件引用那一块去,但实际上还是头文件没有引用的问题,还是觉得有点奇怪。
Receiver 'NSManagedObjectContext' for class message is a forward declaration 错误的解决方案