开发者

why am I getting an "unknown type name NSManagedObjectContext" in this code?

any ideas why am I getting an "unknown type name NSManagedObjectContext" in this code?

I'm basically adding core data to an existing project. I've added the coredata lines + I have added in the CoreData.framework to the project. To do this I went:

  • when to application target
  • build phases
  • link binary with library
  • then added the CoreData framwork
  • then dragged it down on the project navigator so it appeared with the other framework icons in Xcode

Note sure what else I have to do? The CoreDataBooks example code that looks pretty much the same as what I have seems to compile

#import <UIKit/UIKit.h>

@interface myAppAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UINavigationController *navigationController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;

// Core Data
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;  // ERROR: unknown type
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;   // ERROR: unknown type
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;   // ERROR: unknown type

- (void)saveContext;
- (NSURL *)applicationDocumentsD开发者_如何学Pythonirectory;

@end


You then have to import the Core Data framework headers into any files that use Core Data classes.

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>


As Greg said above, the way XCode 4 handles this is by adding #import <CoreData/CoreData.h> into the [projectname]_Prefix.pch file which I found in Other Sources folder/group.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜