每当我构建以下代码时,我都会收到上面的错误。
//Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
#import "PolygonView.h";
@interface Controller : NSObject
{
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet PolygonShape *shape;
IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end
//Controller.m
#import "Controller.h"
@implementation Controller
@end
但是,当我替换 import 语句并提供前向类引用时,代码可以编译。
//Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
@class PolygonView;
@interface Controller : NSObject
{
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet PolygonShape *shape;
IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end
//Controller.m
#import "Controller.h"
#import "PolygonView.h"
@implementation Controller
@end
谁能解释一下?
最佳答案
是的,我也遇到了循环依赖的问题,我在其中相互导入了两个类。我也不知道前向声明是什么。我立即在维基百科上搜索了它,但它的描述很差。我发现这篇文章解释了它们是什么以及它们与周期性进口的关系。 http://timburrell.net/blog/2008-11-23/effective-c-cyclical-dependencies/
注意:链接不断下降,所以我只是 PDF'd it .
关于iphone - 错误 : expected specifier-qualifier-list before. ..在 Objective C 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1246509/