【发布时间】:2014-11-12 15:46:42
【问题描述】:
给定一个 NS_ENUM 枚举宏:
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
元素的顺序是什么?我的意思是每个元素的底层整数值。
例如,UITableViewCellStyleDefault 的值为 0,UITableViewCellStyleValue1 的值为 1,UITableViewCellStyleValue2 的值为 2,UITableViewCellStyleSubtitle 的值为 3?
或者可以是这样的:UITableViewCellStyleDefault 的值为 30,UITableViewCellStyleValue1 的值为 15,UITableViewCellStyleValue2 的值为 23,UITableViewCellStyleSubtitle 的值为 3?
谢谢
【问题讨论】:
-
使用 NS_ENUM 时从 0 开始顺序排列。 NS_OPTIONS 将用于给出任意值。值得注意的是,对于 NS_ENUM,该值并不重要。如果您的代码依赖于某些特定值,则可能是其他问题的代码异味。
-
^ 没错。你应该把它变成一个答案
-
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {...};与typedef enum : Integer {...} UITableViewCellStyle;相同,这就是NS_ENUM所做的。
标签: objective-c macros enums