【发布时间】:2014-08-27 06:58:10
【问题描述】:
PRECAP: 我已关注Why can I not use my constant in the switch - case statement in Objective-C ? ,但问题仍然存在。此外,我不允许在上面的链接中评论我的问题,这就是我再次提出这个问题的原因。
在 iOS 应用程序中,我有 constants.h 为:
int const Category_Default = 1;
在另一个文件中(比如 test.m)我是这样使用的:
switch(//someVariable) {
case Category_Default:
//do something
default:
//do something
}
不幸的是,编译器给了我一个错误,因为 大小写标签不会减少为整数常量。
我知道必须在编译时知道常量的值才能在switch 内的case 中使用。
我什至按照Why can I not use my constant in the switch - case statement in Objective-C 中的建议初始化了 .h 文件本身中的常量,但错误仍然存在。
注意:在这种情况下,我不想使用#define 或enum。
对此的任何帮助将不胜感激。
【问题讨论】:
-
@Shai 是的,它是重复的,但我已经提到我关注了它,但问题仍然存在!
标签: objective-c switch-statement constants