Rit*_*its 8 iphone cocoa-touch objective-c switch-statement nsinteger
为什么这不起作用:
NSInteger sectionLocation = 0;
NSInteger sectionTitles = 1;
NSInteger sectionNotifications = 2;
switch (section) {
case sectionLocation:
//
break;
case sectionTitles:
//
break;
case sectionNotifications:
//
break;
default:
//
}
Run Code Online (Sandbox Code Playgroud)
我得到这个编译错误:
错误:case标签不会减少为整数常量
是不是可以像这样使用NSInteger?如果是这样,是否有另一种方法在switch语句中使用变量作为案例?sectionLocation等具有可变值.
bbu*_*bum 11
问题不是标量类型,而是案例标签在它们是这样的变量时可能会改变值.
对于所有意图和目的,编译器将switch语句编译为一组gotos.标签不可变.
使用枚举类型或#defines.
| 归档时间: |
|
| 查看次数: |
6320 次 |
| 最近记录: |