声明 NSManagedObjectContext 时出错
我正在尝试创建一个 NSManagedObjectContext 对象。他们的错误如下:
预期的说明符限定符列表 在“NSManagedObjectContext”之前
,这是我的头文件:
#import <UIKit/UIKit.h>
@interface FavouritesViewController : UITableViewController {
NSArray *favourites;
NSManagedObjectContext *context;
}
@property (nonatomic, retain) NSArray *favourites;
@property (nonatomic, retain) NSManagedObjectContext *context;
@end
有人知道我可能会在这里失踪吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您很可能忘记在文件中包含 CoreData 标头。在
#import
行之后,您需要另一行读取#import
。之后该文件应该可以正常编译。还要确保链接库中有 CoreData,否则会出现运行时错误。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.您需要在接口指令上方添加
@class NSManagedObject
。这将告诉编译器 NSManagedObject 是一个真正的类。然后,您需要在 .m 文件中添加#import
。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.