Fog*_*ter 3 iphone enums typedef ios
我为我的iPhone应用程序创建了一个typedef枚举...
typedef enum {
FirstType,
SecondType,
ThirdType
} type;
Run Code Online (Sandbox Code Playgroud)
仅仅为了测试,我希望能够从这些中选择随机类型.
我打算用来arc4random() % 4做它,只是在它的位置使用int,但想检查是否有更好的方法来做到这一点.
Sul*_*han 19
typedef enum {
FirstType = 0,
SecondType,
ThirdType,
EnumTypeMax
} EnumType;
EnumType randomType = (EnumType) (arc4random() % (int) EnumTypeMax);
Run Code Online (Sandbox Code Playgroud)
注意,EnumTypeMax等于3,不是4,这是正确的.
EnumTypeMax被视为无效值.
另外,请在此处查看有关X-Macros解决方案的答案.
| 归档时间: |
|
| 查看次数: |
2184 次 |
| 最近记录: |