Objective C - when should "typedef" precede "enum", and when should an enum be named?
- by Scott Pendleton
In sample code, I have seen this:
typedef enum Ename { Bob, Mary, John} EmployeeName;
and this:
typedef enum {Bob, Mary, John} EmployeeName;
and this:
typedef enum {Bob, Mary, John};
but what compiled successfully for me was this:
enum {Bob, Mary, John};
I put that line in a .h file above the @interface line, and then when I #import that .h file into a different class's .m file, methods there can see the enum.
So, when are the other variants needed?
If I could name the enum something like EmployeeNames, and then, when I type "EmployeeNames" followed by a ".", it would be nice if a list pops up showing what the enum choices are.