问题
I'm trying to create a NSManagedObjectContext object. They error reads as follows:
Expected specifier-qualifier-list before 'NSManagedObjectContext'
and here is my header file:
#import <UIKit/UIKit.h>
@interface FavouritesViewController : UITableViewController {
NSArray *favourites;
NSManagedObjectContext *context;
}
@property (nonatomic, retain) NSArray *favourites;
@property (nonatomic, retain) NSManagedObjectContext *context;
@end
Anyone know I might be missing here?
回答1:
Most probably you have forgotten to include the CoreData header in your file. Right after the line #import <UIKit/UIKit.h>
you need another line that reads #import <CoreData/CoreData.h>
. After this the file should compile fine. Also make sure that you have CoreData in your linked libraries, otherwise you will get runtime errors.
回答2:
You need to add @class NSManagedObject
above your interface directive. This will tell the compiler that NSManagedObject is a real class. You then need to have #import <CoreData/CoreData.h>
in your .m file.
来源:https://stackoverflow.com/questions/4101384/error-when-declaring-nsmanagedobjectcontext