- 用枚举表示状态,选项,状态码;
-
枚举是一种常量命名方式,某个对象所经历的各种状态就可以定义为一个简单的枚举集(enumeration设置)例如:
编译器会为每个枚举值分配一个独有的编号,从0开始,依次加1。一个字节最多可表示0~255共256种(2^8)枚举变量。enum EOCConnectionState { EOCConnectionStateDisconnected, EOCConnectionStateConnecting, EOCConnectionStateConnected, };
-
typedef NS_ENUM(NSUInteger, EOCConnectionState) {
EOCConnectionStateDisconnected,
EOCConnectionStateConnecting,
EOCConnectionStateConnected
};
switch (_currentState) {
EOCConnectionStateDisconnected:
//...
break;
EOCConnectionStateConnecting:
//...
break;
EOCConnectionStateConnected:
//...
break;
} - 宏定义:
- 这个是一个判断,if,如果支持新特性:
-