Error when declaring NSManagedObjectContext

你说的曾经没有我的故事 提交于 2019-12-12 23:14:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!