In the Objective-c language, Apple introduced two macros in iOS to redefine the enumeration type (that is, Ns_enum and ns_options), which is essentially the same as defining enumerated types, but in using Ns_enum for general enumerations, Ns_enumm is used for general enumerations, while Es_options is used for enumerations with shift operations.
Ns_enum Use Example
typedef ns_enum (Nsuinteger, Type) {
Typenone = 0,
TypeTime = 1,
TypeText = 2,
Typetimeandtext = 3
};
Ns_options Use Example
typedef ns_options (Nsuinteger, Test) {
Testa = 1 << 0,
TESTB = 1 << 1,
TESTC = 1 << 2,
TESTD = 1 << 3
};
Enumerations with shift operations are used for situations where the same enumeration variable can simultaneously assign multiple enumeration members. The rationale is to bitwise OR (|) The individual enumeration values, because the enumeration members of the shift operation can guarantee the uniqueness of the results after the bitwise OR (|) calculation, so each result is reversed to calculate whether there are several enumeration members bitwise OR ( |) and Into
To accommodate bitwise OR (|) Assign an enumeration member to the enumeration variable test TESTA,TESTB
Test test = Testa | TESTB; To use bitwise XOR or (^) to remove an enumeration member from the enumeration variable test testa
Test ^= Testa;
Note: If the enumeration variable test itself is not assigned a value of Testa, then using bitwise XOR or (^) will assign an enumeration member to the enumeration variable test multiple Testa
To use bitwise AND (&) to determine whether the enumeration variable test is assigned the enumeration member Testa as an example
if (Test & Testa) {
NSLog (@ "yes");
}else {
NSLog (@ "no");
}