示例 .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
为什么我会收到该错误(请参阅上面代码中的注释)?它在类实例变量声明下方时工作正常,但我想将它用作我的实例变量之一的类型。
最佳答案
感谢@CarlVeazey,我发现答案很简单:将 typedef
声明移至 @interface
上方。这样做的原因是类型不能由类或类的实例拥有,因此不能在类的接口(interface)中。
关于ios - 在类实例变量之前声明时出现 NS_ENUM 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18368267/