[Objective-C] Expected expression Error in switch Statement

Tadashi Shigeoka ·  Mon, May 20, 2013

I encountered an Expected expression error in an Objective-C switch statement.

switch(i){
    case 0:
        int spam = 0;
        break;
    default:
        break;
}

Declaring variables inside case blocks causes an Expected expression error, so you can eliminate the error by moving the variable declaration outside the switch statement like this:

int spam;

switch(i){
    case 0:
        spam = 0;
        break;
    default:
        break;
}

[Reference]

Expected expressionというエラーがでる | 人生休暇中

That’s all from the Gemba.