开发者

Cocoa-Touch, Core Data: Compiler cannot find the NSManagedObjectContext (+ other core data classes)

开发者 https://www.devze.com 2022-12-08 16:01 出处:网络
I have an application that will use Core Data. I\'ve added the Core Data framework to the linked library list in XCode.

I have an application that will use Core Data.

I've added the Core Data framework to the linked library list in XCode.

In one of my classes, I try to set up the NSManagedObjectContext along with the other required classes as folows:

@interface MyClass : NSObject {
    NSManagedObjectModel *managedObjectModel;
    NSManagedObjectContext *managedObjectContext;
    NSPersistentStoreCoordinator *persistentStoreCoordinator;
}

@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) 开发者_Go百科NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

I'm using the Locations sample app as a reference, it also uses Core Data, it also has it linked the same way I have.

What am I doing wrong?


This got me the first time I tried it too. The header files for Core Data are #imported in the sample projects precompiled header file (Locations_Prefix.pch). You just need to copy that line into your app too.

You should be able to guess the line, but it's this:

#import <CoreData/CoreData.h>

I guess it's a handy place to put it, but a bit obscure for demonstration purposes!

0

精彩评论

暂无评论...
验证码 换一张
取 消