作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 C++ 中,我可能会在 header 中执行以下操作:
cClass {
enum eList { FIRST, SECOND };
}
...这在其他类(class)中:
cClass::eList ListValue = GetListValue();
if(ListValue == cClass::FIRST) {
...
}
是否有使用直接 Objective-C 语言功能或 Cocoa 中的一些技巧的等效方法,可以允许类似的作用域 枚举
?
最佳答案
嗯,您可以使用 C: 来模拟它的部分内容
创建一个 C 枚举并输入:
enum MONEnumType : uint8_t {
MONEnumType_Undefined = 0,
MONEnumType_Red,
MONEnumType_Green,
MONEnumType_Blue
};
声明容器:
struct MONEnum {
const enum MONEnumType Red, Green, Blue;
};
声明存储:
extern const struct MONEnum MONEnum;
定义存储:
const struct MONEnum MONEnum = {
.Red = MONEnumType_Red,
.Green = MONEnumType_Green,
.Blue = MONEnumType_Blue
};
使用中:
enum MONEnumType ListValue = GetListValue();
if (ListValue == MONEnum.Red) {
/* ... */
}
关于objective-c - 是否有与 C++ 的类范围枚举等效的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12973999/
我是一名优秀的程序员,十分优秀!