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
switchstatements —You cannot declare local variables inside an individual
caseunless you put them inside{}brackets.Simplest thing to do is to put the
UIViewController *vc;declaration ahead of theswitchand just putvc = [[whatever..inside thecase.