ios 我可以在 Objective C 中使用枚举作为属性吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10801651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use an enum as a property in Objective C
提问by bursyllac
I saw it is customed to use a boolean property as a flag. something like that:
我看到它习惯于使用布尔属性作为标志。类似的东西:
@property (nonatomic) BOOL commaAlreadyIntroduced;
I need something like that but with at least 3 or 4 states.
我需要类似的东西,但至少有 3 或 4 个状态。
Can I use an enum?
我可以使用枚举吗?
The standalone enum should look like:
独立枚举应如下所示:
typedef enum stackState{
empty, oneOperand, operandAndOperator, fullStack
}stackState;
回答by Pfitz
Yes, it's not a problem:
是的,这不是问题:
@property (nonatomic, assign) stackState yourIvar;
回答by Arvin Sanmuga Rajah
@property (nonatomic, assign) enum stackState stackStateVar;
Without 'enum' added, my unit tests kept showing errors.
没有添加“枚举”,我的单元测试一直显示错误。
回答by FishStix
@property (nonatomic, assign) enum stackState yourIvar;
@property (nonatomic, assign) enum stackState yourIvar;
(was getting errors until I added enum)
(在我添加enum之前一直出错)