How to make a big switch control structure with variable check values?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-05-24T12:52:28Z Indexed on 2010/05/24 15:21 UTC
Read the original article Hit count: 307

For example, I have a huge switch control structure with a few hundred checks. They're an animation sequence, which is numbered from 0 to n.

Someone said I can't use variables with switch. What I need is something like:

NSInteger step = 0;
NSInteger i = 0;
switch (step) {
case i++:
    // do stuff
    break;

case i++:
    // do stuff
    break;

case i++:
    // do stuff
    break;

case i++:
    // do stuff
    break;

}

The point of this is, that the animation system calls a method with this big switch structure, giving it a step number. I want to be able to simply cut-copy-paste large blocks and put them in a different position inside the switch. for example, the first 50 blocks to the end.

I could do that easily with a huge if-else structure, but it would look ugly and something tells me switch is much faster.

How to?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c