Objective-C Tip: Switch Statements | | Scyanide Chatter
During one of my sessions of working on the iPhone game. I noticed something very strange within Objective-C. [crayon-5d0a929d89df9648689305/] Apparently, this will get a compiler error as it expects an expression to be place before the declaration. I did a little searching around and was unable to find much on why this causes an error. I did however, find a few solutions that seem to work really well. Considering the error is that the compiler expected an expression before the declaration you can try to rearrange your statements so that declarations are not the first statements within the case statement. [crayon-5d0a929d89e0a119819385/] ...or you can just place an empty semicolon if the above example is not an option. [crayon-5d0a929d89e0f508465461/] Last, I found a better solution to the above examples and it is the one I'll be using. I really don't know exactly why this one works as it is not really an expression but by adding { and } to separate the block of code within the case