iphone - 错误 : expected specifier-qualifier-list before. ..在 Objective C 中?

标签 iphone objective-c

每当我构建以下代码时,我都会收到上面的错误。

//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/

相关文章:

iphone - 为什么我们在 objective-c 中使用 int sqlite3_bind_int(sqlite3_stmt*, int, int) ?

objective-c - 使用未声明的标识符

iphone - 通过 safari 安装 AD-HOC 分发时遇到问题

Iphone ABUnknownPersonViewController 使用 allowsAddingToAddressBook = YES 问题

iphone - 适用于 iOS 的具有 Retina 显示屏的本地化应用程序图标

ios - "On my iPhone"选项在模拟器中不可见。

ios - 逐渐提高 SpriteKit 对象的速度

ios - 滚动 uiscrollview 时淡化 UITextView

iphone - 音乐播放器只播放一首轨道

ios - 将 UITabBar 定位在顶部