I would like to have class static variables as states, but Objective C disallowed it
I tried +(int)LOOPING_STATE for state class, but it will fail in
switch (myCurrentState) {
case [STATE_CLASS LOOPING_STATE]: <== received an error of "expression can't be put here"
return;
}
Is enum generally the choice for writing state codes?
Are there any other options, and under what condition should those options be used?
Thanks in advance.
If this state machine needs to be fast, enums are the way to go. However, if you want an object oriented way of doing this, the functionality of each state would be a method of the state object itself. Thus you would do away with the switch/if statement altogether. Your state machine’s loop would look something like this:
inputsis the input data for the state transition,actionsis a block or a selector or anNSInvocationor something that tells the state what to do during the transition.