NS_ENUM和NS_OPTIONS使用

 

参考:http://nshipster.com/ns_enum-ns_options/

 

NS_ENUM

typedef NS_ENUM(NSInteger, Fruit){
    Apple,
    Orange,
    Banana,
};

 

NS_OPTIONS

// 定义
typedef NS_OPTIONS(NSUInteger, Margin) {
    GKMarginNone = 0,
    GKMarginTop = 1<<0,
    GKMarginLeft = 1<<1,
    GKMarginBottom = 1<<2,
    GKMarginRight = 1<<3,
};

  // 定义
    Margin margin = GKMarginLeft | GKMarginTop | GKMarginRight;
    
    // 解析
    if (margin & GKMarginLeft) {
        NSLog(@"GKMarginLeft");
    }
    if (margin & GKMarginTop) {
        NSLog(@"GKMarginTop");
    }
    if (margin & GKMarginBottom) {
        NSLog(@"GKMarginBottom");
    }
    if (margin & GKMarginRight) {
        NSLog(@"GKMarginRight");
    }

 

位运算知识复习:

http://baike.baidu.com/view/379209.htm?fr=aladdin

你可能感兴趣的:(option)