1. 症状
Objective-C の switch構文の内側でブロックを定義するとコンパイルエラー "Cannot jump from switch statement to this case label" が発生する。
2. 対策
case文の内側を { } で括る。
2.1. 修正前
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
switch (flag) { case 1: [aObject completion: ^{ NSLog("1 is selected"); }]; break; case 2: // ← Cannot jump from switch statement to this case label [aObject completion: ^{ NSLog("2 is selected"); }]; break; default; [aObject completion: ^{ NSLog("Anything is not selected"); }]; break; } |
2.2. 修正後
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
switch (flag) { case 1: { [aObject completion: ^{ NSLog("1 is selected"); }]; break; } case 2: { [aObject completion: ^{ NSLog("2 is selected"); }]; break; } default; { [aObject completion: ^{ NSLog("Anything is not selected"); }]; break; } } |