I have this enumeration:
enum battleType {localEnemy,multiplayerEnemy};
Which is declared in the .h file of my game battle scene. However, I would like to also use those two keywords in my party screen (which is another .h file). Do I have to declare this same enumaration twice (in both .h files), or is there a way to just declare it once and use it everywhere in my project?
As a side note, those keywords are exactly the same as integers, right? So I can’t really store them as objects in my array, and instead I have to create a NSNumber instance for this, right?
Declare it in the header file it belongs into. In your case that would probably be BattleScene.h or something like that.
In the other file where you also have to use it you
#import BattleScene.h.If you use typedef, you don’t have to write
enumall the time. Also, it a good practice to use a uniform prefix in your enums. This makes your code more readable and autocomplete can help you when using the enum.