Enum type creates an enumeration using the Emum keyword.
// defines an enumeration that represents a direction Enumdirection{up,down,middle,left,right};
The value of the enumeration can be represented by a number, and is incremented by default from zero
Enumdirection Direction =Up ;//Output 0NSLog (@"Direction =%i", direction);d irection=Down ;//Output 1NSLog (@"Direction =%i", direction);d irection=Middle;//Output 2NSLog (@"Direction =%i", direction);d irection=Left ;//Output 3NSLog (@"Direction =%i", direction);d irection=Right ;//Output 4NSLog (@"Direction =%i", direction);
- The value of the custom enumeration.
The value of the enumeration is incremented by default from zero, the next enumeration value is the previous enumeration value +1, and if we customize the enumeration value, then the next enumeration value is the previous custom enumeration value +1
enumdirection{up,// 0down=,//Middle,//11 left,//+ right//;
Convert numbers to enumerations
Because enumerations are represented by numbers, numbers can also be converted to enumerations.
// Defining Enumerations Enumdir{up,down}; // number to enumerate enumdir dir =0; // detect if they are equal if (dir = = up ) {NSLog (@ " equals ... " );}
typedef definition Aliases typedef can define aliases for complex declarations, such as the enumerations above us.
// enable alias typedefenumdirdirection for enum Dir ;
With the alias definition as above, we can use the Dir enumeration in the subsequent use
// enumeration using aliases Direction Direction = up;
typedef can define not only enum aliases, int, float and other types can be defined
The Nsinteger we will use later is the alias definition of Int. The "icon in the Xcode code Editor represents a typedef alias.
From for notes (Wiz)
Enum and typedef