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 #import
ed 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!
精彩评论