Moving on with my game a bit I want to add difficulties etc.
Coming to Objective-C from C#, I was hoping I could have some enums like this
typedef enum GameTypes{
Classic = 0,
Unlimited,
Timed,
Expert,
} GameType;
typedef enum GameDifficultys
{
Easy = 0,
Medium,
Hard,
} GameDifficulty;
and then have something like this:
GameType gameType = GameTypes.Classic;
GameDifficulty gameDifficulty = GameDifficultys.Easy;
However I get this following error:
Unknown type name "GameType"/"GameDifficulty"
Is this possible like it is in C#?
Thanks
C#is one of the worst things to ever happen toC.Your question has nothing to do with Objective-C, it’s a plain C question.
That code does several things (of which I will only describe the easy ones). First, it declares an enumeration type, which can be used as
enum GameTypes. For example:Second, it puts those 4 names into the global namespace, such that
Classic,Unlimited,Timed, andExpertcan be used, and must not be duplicated as symbols.Third, it creates a type alias called
GameTypewhich can be used as an alias forenum GameTypes.So, for your specific example, you should not differentiate
enum GameTypesandGameType. Instead, you should probably do something like this:and then…
Also, you do not have to assign the first element as
0because the first element of an enumeration will always get0unless it is explicitly overridden.