1. 程式人生 > >Objetive-C列舉位移操作&Swift列舉位移操作

Objetive-C列舉位移操作&Swift列舉位移操作

Objective-C 列舉

typedef NS_ENUM(NSInteger,LineDirection){
    LineDirectionTop = 1 << 0,
    LineDirectionBottom = 1 << 1,
    LineDirectionLeft = 1 << 2,
    LineDirectionRight = 1 << 3
};

objective-C & 與運算判斷舉例

 if (direction & LineDirectionTop) {

 }

Swift 列舉

enum LineDirection:UInt8 {

    case
top = 0b0001 case bottom = 0b0010 case left = 0b0100 case right = 0b1000 }

Swift & 與運算判斷舉例

 if (direction.rawValue & LineDirection.top.rawValue) != 0b000 ){

 }