标签:
枚举是一种常量命名方式,某个对象所经历的各种状态就可以定义为一个简单的枚举集(enumeration设置)例如:
enum EOCConnectionState {
EOCConnectionStateDisconnected,
EOCConnectionStateConnecting,
EOCConnectionStateConnected,
};
编译器会为每个枚举值分配一个独有的编号,从0开始,依次加1。一个字节最多可表示0~255共256种(2^8)枚举变量。typedef NS_ENUM(NSUInteger, EOCConnectionState) {
EOCConnectionStateDisconnected,
EOCConnectionStateConnecting,
EOCConnectionStateConnected
};
switch (_currentState) {
EOCConnectionStateDisconnected:
//...
break;
EOCConnectionStateConnecting:
//...
break;
EOCConnectionStateConnected:
//...
break;
}
标签:
原文地址:http://www.cnblogs.com/xsyl/p/5788665.html