##定义:
//NS_OPTIONS,定义选项 typedef NS_OPTIONS(NSUInteger, MyOption) { MyOptionNone = 0, //二进制0000,十进制0 MyOption1 = 1 << 0,//0001,1 MyOption2 = 1 << 1,//0010,2 MyOption3 = 1 << 2,//0100,4 MyOption4 = 1 << 3,//1000,8 }; 复制代码
##使用:
//声明定义枚举变量 MyOption option = MyOption1 | MyOption2;//0001 | 0010 = 0011,3 //检查是否包含某选型 if ( option & MyOption3 ){ //0011 & 0100 = 0000 //包含MyOption3 }else{ //不包含MyOption3 } //增加选项: option = option | MyOption4;//0011 | 1000 = 1011, 11 //减少选项 option = option & (~MyOption4);//1011 & (~1000) = 1011 & 0111 = 0011, 3 复制代码