why is typedef needed in the code below?
typedef enum _Coordinate {
CoordinateX = 0, ///< X axis
CoordinateY = 1, ///< Y axis
CPCoordinateZ = 2 ///< Z axis
} Coordinate;
why not just have the code below and remove the typedef?
enum Coordinate {
CoordinateX = 0, ///< X axis
CoordinateY = 1, ///< Y axis
CPCoordinateZ = 2 ///< Z axis
};
If you don’t
typedefyour enum, in your other code you have to refer to it asenum Coordinateinstead of justCoordinate, even though you knowCoordinateis an enum. It’s just to eliminate the redundancy of theenumkeyword when referring to it, I guess.To make it clearer, here’s what it would look like if you
typedefit separately from declaring it:This also applies to C structs and enums (Obj-C enums are just C enums anyway).