In general, we use the C-style enum keyword to define enumeration types.
enum{
Uiviewanimationtransitionnone,
Uiviewanimationtransitionflipfromleft,
Uiviewanimationtransitionflipfromright,
Uiviewanimationtransitioncurlup,
Uiviewanimationtransitioncurldown,
} uiviewanimationtransition;
Displacement Operation Enumeration Definition
enum {
Uiviewautoresizingnone = 0,
Uiviewautoresizingflexibleleftmargin = 1 << 0,
Uiviewautoresizingflexiblewidth = 1 << 1,
Uiviewautoresizingflexiblerightmargin = 1 << 2,
Uiviewautoresizingflexibletopmargin = 1 << 3,
Uiviewautoresizingflexibleheight = 1 << 4,
Uiviewautoresizingflexiblebottommargin = 1 << 5
};
typedef nsuinteger UIVIEWAUTORESIZING;//Use Nsuinteger where you can use uiviewautoresizing,// Uiviewautoresizing is equivalent to an alias used by Nsuinteger.
So a uiviewautoresizing variable can be assigned directly to Nsuinteger.
An enumeration value is typically an int value of 4 bytes, which is 8 bytes on a 64-bit system.
After IOS6 and Mac OS 10.8, Apple introduced two macros to redefine the two enum types, essentially combining the enum definition with a typedef and using different macros to differentiate from the code perspective.
Ns_options is generally used to define the enumeration values of displacement-related operations, we can refer to the Uikit.framework header file, you can see a large number of enumeration definitions.
typedef ns_enum (Nsinteger, uiviewanimationtransition) {
uiviewanimationtransitionnone,//default starting from 0
Uiviewanimationtransitionflipfromleft,
Uiviewanimationtransitionflipfromright,
Uiviewanimationtransitioncurlup,
Uiviewanimationtransitioncurldown,
};
typedef ns_options (Nsuinteger, uiviewautoresizing) {
Uiviewautoresizingnone = 0,
Uiviewautoresizingflexibleleftmargin = 1 << 0,
Uiviewautoresizingflexiblewidth = 1 << 1,
Uiviewautoresizingflexiblerightmargin = 1 << 2,
Uiviewautoresizingflexibletopmargin = 1 << 3,
Uiviewautoresizingflexibleheight = 1 << 4,
Uiviewautoresizingflexiblebottommargin = 1 << 5
};
The two macros are defined in Foundation.framework's NSObjCRuntime.h:
- #if (__cplusplus && __cplusplus >= 201103L && (__has_extension (cxx_strong_enums) | | __has_ Feature (objc_fixed_enum)) | | (!__cplusplus && __has_feature (objc_fixed_enum))
- #define Ns_enum (_type, _name) enum _name: _type _name; enum _name: _type
- #if (__cplusplus)
- #define Ns_options (_type, _name) _type _name; enum: _type
- #else
- #define Ns_options (_type, _name) enum _name: _type _name; enum _name: _type
- #endif
- #else
- #define Ns_enum (_type, _name) _type _name; ENUM
- #define Ns_options (_type, _name) _type _name; enum
- #endif
Will
typedef ns_enum (Nsinteger, uiviewanimationtransition) {
Expand to get:
typedef enum Uiviewanimationtransition:nsinteger Uiviewanimationtransition;
Enum Uiviewanimationtransition:nsinteger {
From the enumeration definition, the essence of Ns_enum and Ns_options is the same, just literally distinguishing its use. Ns_enum is a general case, ns_options is generally used to define situations with displacement operations or characteristics (bitmask).
When actually used, you can define directly:
typedef enum:nsinteger {....} Uiviewanimationtransition;
is equivalent to the definition above.
Reference Documentation:
1. http://nshipster.com/ns_enum-ns_options/
2.http://iamthewalr.us/blog/2012/11/ns_enum-and-ns_options/
3.http://blog.csdn.net/annkie/article/details/9877643
IOS enum type enum Ns_enum ns_options