OC高效率52之用枚举表示状态码&&选项

enum EOCConnectionState{
    EOCConnectionStateDisconnected = 2,
    EOCConnectionStateConnecting,
    EOCConnectionStateConnected,
    EOCConnectionStateConnectFail,
};
typedef enum EOCConnectionState EOCConnectionState;

enum EOCWiFiState {
    EOCWiFiStateDisconnected,
    EOCWiFiStateConnecting,
    EOCWiFiStateConnected,
};

typedef enum EOCWiFiState :int EOCWiFiState;  // 指定底层数据类型所用的方法



#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    enum EOCConnectionState state = EOCConnectionStateConnected;
    EOCConnectionState state1 = EOCConnectionStateConnecting;//typedef 后的表示
    
//    NS_OPTIONS(<#_type#>, <#_name#>)  凡是须要以按位或操做来组合的枚举都应该应用此定义
//    NS_ENUM(<#...#>)
    
    switch (state) {
        case EOCConnectionStateConnecting:
            NSLog(@"Connecting");
            break;
        case EOCConnectionStateConnected:
            NSLog(@"");
            break;
        case EOCConnectionStateDisconnected:
            NSLog(@"");
            break;
//        default:
//            break;
            //若用枚举来定义状态,则最好不要用default分支,若是用了,新加了状态,编译器不会发出警告提示有状态未加入switch语句
    }
}
//视图支持的方向    系统方法的枚举二进制表示
-(UIInterfaceOrientationMask) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
相关文章
相关标签/搜索