gpt4 book ai didi

ios - 在类实例变量之前声明时出现 NS_ENUM 错误

转载 作者:行者123 更新时间:2023-11-29 10:56:06 27 4
gpt4 key购买 nike

示例 .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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com