I\'ve got a prepareForSegue method in two different VCs. One uses an if
statement, while the other is intended to use a switch
. The code is virtually i
There are two separate problems here.
You can declare a variable in C/Objective-C
in a switch-statement (without the need for an additional { ... }
scope),
but not immediately following a label. To solve this problem it is sufficient
to insert a semicolon after the label:
switch (i) {
case 0: ;
int i;
// ...
break;
default:
break;
}
Only if you declare Objective-C objects and compile with ARC, then you have to introduce an additional scope:
switch (i) {
case 0: {
NSObject *obj;
// ...
} break;
default:
break;
}
The reason is that the ARC compiler needs to know the precise lifetime of the object.