Enumerated Constants
Objective-C中的枚举常量大致有以下四种情形:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
情形一相当于定义了常量,但不定义类型;
情形二定义了一个NSMatrixMode类型;
情形三定义了一个NSInteger的UITableViewCellStyle类型;
情形四支持C++的枚举特性。
The NS_OPTIONS macro is defined in different ways if compiling as C++ or not. If it’s not C++, it’s expanded out the same as NS_ENUM. However, if it is C++, it’s expanded out slightly differently. Why? The C++ compiler acts differently when two enumeration values are bitwise OR’ed together. This is something, as shown earlier, that is commonly done with the options type of enumeration. When two values are OR’ed together, C++ considers the resulting value to be of the type the enumeration represents: NSUInteger. It also doesn’t allow the implicit cast to the enumeration type.
Reference:
Effective Objective-C 2.0
NS_ENUM & NS_OPTIONS