方法声明中的语法错误:预期为“)”名字前
我对遇到的错误感到非常困惑。我有以下代码:
在 View1.m 中,我进行此调用:
[iconView addIconWithType:IconTypeStandard];
IconView.h
typedef enum {
IconTypeStandard = 0,
IconTypeNew = 1,
} IconType;
-(void)addIconWithType:(IconType)iconType;
IconView.m
-(void)addIconWithType:(IconType)iconType {
...
}
Icon.h
#import "IconView.h"
@interface Icon : UIView {
}
-(Icon *)initWithFrame:(CGRect)frame;
-(void)type:(IconType)iconType;
该行导致“IconType”之前出现“预期”)“错误,但我不知道为什么?
图标.m
-(void)type:(IconType)iconType {
...
}
I'm very confused about an error I'm getting. I have the following code:
In View1.m I make this call:
[iconView addIconWithType:IconTypeStandard];
IconView.h
typedef enum {
IconTypeStandard = 0,
IconTypeNew = 1,
} IconType;
-(void)addIconWithType:(IconType)iconType;
IconView.m
-(void)addIconWithType:(IconType)iconType {
...
}
Icon.h
#import "IconView.h"
@interface Icon : UIView {
}
-(Icon *)initWithFrame:(CGRect)frame;
-(void)type:(IconType)iconType;
That line is causing an error of 'Expected ')' before 'IconType'', but i have no idea why?
Icon.m
-(void)type:(IconType)iconType {
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜测存在周期性包含。
Icon.h
引用IconView.h
,反之亦然。由于typedef
出现在Icon.h
中的 import 语句之后,因此它会引发错误,因为它还找不到IconType
。您可能应该声明
@class IconView;
并将#import "IconView.h"
移动到Icon.m
。I am guessing there is a cyclical inclusion.
Icon.h
refers toIconView.h
and vice versa. Since thetypedef
comes after the import statement inIcon.h
it is raising the error as it can't findIconType
yet.You should probably declare
@class IconView;
and move the#import "IconView.h"
toIcon.m
.您的枚举中有一个尾随逗号
You have a trailing comma in your enum