Is there any way to use global int constants in Objective C that work in a case/switch statement? The technique here (http://stackoverflow.com/questions/538996/constants-in-objective-c) lets me access the constants everywhere, but does not let me put them into a switch statement.
in .h
FOUNDATION_EXPORT const int UNIT_IDLE;
FOUNDATION_EXPORT const int UNIT_DEFEND;
in .m
int const UNIT_IDLE = 0;
int const UNIT_DEFEND = 1;
Error is “Expression is not an integer constant expression”
I usually use enumerations with typedef statements when using constants which I will use in a switch statement.
For example, this would be in a shared .h file such as ProjectEnums.h:
I can then use code similar to the following switch statement in my .c, .m, .cpp files:
This also allows the compiler to verify the data being passed to the method and used within the switch statement at compile time.