枚舉的作用:增強(qiáng)代碼的可讀性菊值,
1.C語言的寫法
enum LJCPPReconnectFlags
{
kShouldReconnect = 1 << 0, // If set, disconnection was accidental, and autoReconnect may be used
kMultipleChanges = 1 << 1, // If set, there have been reachability changes during a connection attempt
kManuallyStarted = 1 << 2, // If set, we were started manually via manualStart method
kQueryingDelegates = 1 << 3, // If set, we are awaiting response(s) from the delegate(s)
};
2.OC中有兩種寫法
<p>1、typedef NS_ENUM(NSInteger, ****Type) 模式, 第一個(gè)枚舉值只要NSInteger類型救巷,后面的依次累加,中間再重新賦值,后面的會(huì)從賦值處重新累加</p>
typedef NS_ENUM(NSInteger, LJCMessageBodyType) {
LJCMessageBodyTypeText = 1, //文本
LJCMessageBodyTypeImage, //圖片
LJCMessageBodyTypeSound, //語音
LJCMessageBodyTypeMap, //地理信息(文本)
LJCMessageBodyTypeNotification, //通知
LJCMessageBodyTypeCustom, //自定義
LJCMessageBodyTypeVideo, //視頻
LJCMessageBodyTypeExpression, //表情
};
<p>2、typedef NS_OPTIONS(NSInteger, *****Type) 模式, 具有位移操作谴返,</p>
typedef NS_OPTIONS(NSUInteger, LJCType) {
LJCTypeWX = 1,
LJCTypeWXFC = 1 << 0,
LJCTypeQQ= 1 << 1,
LJCTypeWB= 1 << 1,
LJCTypeReport= 1 << 3,
LJCTypeBarrage = 1 << 4,
LJCTypeAll = 0xFFFFFFFF,
};
<p> <<(左移):a << b就表示把a(bǔ)轉(zhuǎn)為二進(jìn)制后左移b位(在后面添b個(gè)0)</p>
<p> LJCTypeAll = 0xFFFFFFFF 表示全選 </p>
<p> 如果我們?cè)诿杜e值中看見<<那我們就可以通過|(位運(yùn)算符:或)進(jìn)行組合使用如下代碼為例: </p>
//隨便添加一個(gè)UITextField
UITextField *field = [UITextField new];
//Begin,Changed,DidEnd都能觸發(fā)UITextField的事件
[field addTarget:self action:@selector(textFieldDidChanged) forControlEvents: UIControlEventEditingDidBegin |
UIControlEventValueChanged |
UIControlEventEditingDidEnd
];
[self.view addSubview:field];