ios枚举

来源:互联网 发布:站长源码 编辑:程序博客网 时间:2024/05/17 06:13

枚举的定义,C语言方式:

typedef enum{
EnumTypeA = 0,
EnumTypeB,    
EnumTypeC,
EnumTypeD
} EnumType;
EnumType是枚举类型的名称。值依次为0,1,2,3,
iOS特有的方式:
typedef NS_ENUM(NSInteger, EnumType){
EnumTypeA = 0,
EnumTypeB,    
EnumTypeC,
EnumTypeD
} ;
NS_ENUM定义枚举,NSInteger枚举类型,EnumType枚举名字。
位表示法:
typedef NS_ENUM(NSInteger, EnumType){
EnumTypeA = 1,
EnumTypeB = 1 << 1,    //1
EnumTypeC = 1 << 2,//4
EnumTypeD = 1 << 3//8
} ;
枚举取多值
 EnumType  type = EnumTypeA  | EnumTypeB;


0 0
原创粉丝点击