我有开关。其中一种情况必须是数组计数:
int count = [array count];
switch (someValue) {
case 0:
[self foo];
break;
case count:
[self bar];
break;
default:
break;
}
但是编译器告诉:
Expression is not an integer constant expression
如何从[数组计数]生成const int?
最佳答案
正如错误所示,所有情况都必须是常量。您需要一个 if
语句来检查动态情况:
int count = [array count];
switch (someValue) {
case 0:
[self foo];
break;
default:
if (someValue == count)
[self bar];
break;
}
关于objective-c - 如何将 [数组计数] 粘贴到 case :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11653465/