我想用下面的表达
-(void)SwitchCondn{ int expression; int match1=0; int match2=1; switch (expression) { case match1: //statements break; case match2: //statements break; default: // statements break; }但是我得到了
当我研究时发现
In order to work in Objective-C, you should define your constant either like this: #define TXT_NAME 1 Or even better, like this: enum {TXT_NAME = 1};我很长时间以来一直在使用这种方法.现在我的变量值会在运行时改变,所以我需要以其他方式定义,我不想使用 if else 那么有没有其他方式声明变量的方法
I have been using this methods since long time . Now my variable value will change in run time so I need to define in others way and i didn't want to use if else so is there any way of declaration variable others way
我有以下学习
为什么我不能在 Objective-C 的 switch-case 语句中使用我的常量?[错误 = 表达式不是整数常量表达式]
Objective C switch 语句和命名整数常量
Objective C 全局常量与 case/switch
整数常量不会减少为整数"
推荐答案expression is not an integer constant expression 错误的意思就是它所说的:在 case 中,该值必须是常量,例如,不能是变量.
The error expression is not an integer constant expression means just what it says: in a case, the value must be constant, as in, not a variable.
您可以将 switch 上方的声明更改为常量:
You could change the declarations above the switch to be constants:
const int match1=0; const int match2=1;或者你可以使用枚举.或者一个 #define.但是你不能在那里使用非常量变量.
Or you could use an enumeration. Or a #define. But you can't use non-constant variables there.
更多推荐
表达式不是 iOS 目标 c 中的整数常量表达式
发布评论