Objective c 如何将[array count]粘贴到案例:

Objective c 如何将[array count]粘贴到案例:,objective-c,ios,arrays,switch-statement,Objective C,Ios,Arrays,Switch Statement,我有开关。其中一种情况必须是数组计数: int count = [array count]; switch (someValue) { case 0: [self foo]; break; case count: [self bar]; break; default: break; } 但我认为: Ex

我有开关。其中一种情况必须是数组计数:

    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

如何从[array count]中生成常量int?

正如错误所示,所有的情况都必须是常量。您需要一个
if
语句来检查动态案例:

if(some value == 0) {
    [self foo];
} else if (someValue == [array count]) {
    [self bar]
}
    int count = [array count];
    switch (someValue) {
        case 0:
            [self foo];
            break;
        default:
            if (someValue == count)
                [self bar];
            break;
    }

不可能。交换机不是这样工作的,您必须创建自己的交换机式控制结构(如果您愿意,我可以这样做)。