tags:

views:

41

answers:

2

If i try to create variable in case statement it gives me build erroe Can anyone clue me in why this syntax gets me a build error ("expected expression before 'NSMutableArray'").

+1  A: 

Assuming you try do something like:

switch (...){
  case someCase:
        NSMutableArray *array = ...
        break;
...
}

c (and so objective-c) does not allow to declare variables inside switch-case statement. If you want to do that you must limit the variable scope by putting your code inside {} block:

switch (...){
  case someCase:{
        NSMutableArray *array = ...
  }
        break;
...
}
Vladimir
+2  A: 

add brackets {} in your case statement to be able to declare variables

Benoît
Thanks Benoit. Adding curly braces fixed the issue
Swapna