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
相關文章
相關標籤/搜索