Objective-C question : Cannot initialize UIViewController in switch case?
switch(anIntegerIndex) {
case 1:
UIViewController *vc = [[UIViewController alloc] init];
break;
default:
break;
}
the above has compile error in the UIViewController line. I'm using iOS 5 SDK + xCode 4.2
It's a common C restriction for switch
statements --
You cannot declare local variables inside an individual case
unless you put them inside {}
brackets.
Simplest thing to do is to put the UIViewController *vc;
declaration ahead of the switch
and just put vc = [[whatever..
inside the case
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With