1

.h 文件示例:

@interface MyClass : NSObject


typedef NS_ENUM(int, myType) {
    Something,
    SomethingElse,
    SomethingElseElse,
    YetAnotherSomethingElse
};

{ //Error On This Line: Expected Identifier or '('

    int aInstanceVariable;

}


//Some Methods go here
@end

为什么我会收到该错误(请参阅上面代码中的注释)?它在类实例变量声明下工作正常,但我想将它用作我的实例变量之一的类型。

4

1 回答 1

2

感谢@CarlVeazey,我发现答案很简单:将typedef声明移到上面@interface。原因是类型不能由类或类的实例拥有,因此不能在类的接口中。

于 2013-08-21T22:02:17.410 回答