当前位置: 首页 > news >正文

用幽默的语言来形容网站开发药品销售推广方案

用幽默的语言来形容网站开发,药品销售推广方案,吉林省建设厅网站专家,成立网站公司需要什么一、场景 当我们使用枚举这个东西时,有时需要多个枚举值任一一个满足时就ture,但是常用的枚举NS_ENUM定义好的枚举只能挨个判断,写一坨就既不美观也不好阅读,如下: typedef NS_ENUM (NSInteger, RPTestType){RPTestT…

一、场景

当我们使用枚举这个东西时,有时需要多个枚举值任一一个满足时就ture,但是常用的枚举NS_ENUM定义好的枚举只能挨个判断,写一坨就既不美观也不好阅读,如下:

typedef NS_ENUM (NSInteger, RPTestType){RPTestTypeUnknown = 0, // unknowRPTestTypeValue0,      // 值0RPTestTypeValue1,      // 值1RPTestTypeValue2,      // 值2RPTestTypeValue3,      // 值3RPTestTypeValue4,      // 值4RPTestTypeValue5,      // 值5
};RPTestType testTeype = RPTestTypeUnknown;
if (testTeype == RPTestTypeValue0 ||testTeype == RPTestTypeValue1 || testTeype == RPTestTypeValue2 || testTeype == RPTestTypeValue3 || testTeype == RPTestTypeValue4 || testTeype == RPTestTypeValue5) {NSLog(@"ture");
}

二、利用NS_OPTIONS优化

1、先了解一个关于位运算符的知识点:位运算符浅析

这里用到(左移 << )和 (按位与 & )和(按位或 | )这仨,先明确是怎么个事;

2、先看下NS_OPTIONS如何来定义枚举
typedef NS_OPTIONS (NSInteger, RPTestType){RPTestTypeUnknown = 1 << 0, // unknowRPTestTypeValue0  = 1 << 1, // 值0RPTestTypeValue1  = 1 << 2, // 值1RPTestTypeValue2  = 1 << 3, // 值2RPTestTypeValue3  = 1 << 4, // 值3RPTestTypeValue4  = 1 << 5, // 值4RPTestTypeValue5  = 1 << 6, // 值5
};

这里使用左移定义枚举值,结合位运算可以这么看:
1 << 0 就是 0001,即2的0次方;
1 << 1 就是 0010,即2的1次方;
1 << 2 就是 0100,即2的2次方;
以此类推~

3、再看这么用的好处

当有多个枚举值都符合时做判断时候,可以直接(或 | )起来,然后(与 & )一下子,就能清晰明了的做判断;

RPTestType testType = RPTestTypeUnknown;
RPTestType judgeType = RPTestTypeValue0 | RPTestTypeValue1 | RPTestTypeValue2 | RPTestTypeValue3 | RPTestTypeValue4 | RPTestTypeValue5;
if (testType & judgeType) {NSLog(@"ture");
}

当然最好使的用处是枚举值传参,如SDImage

[self.testImgView sd_setImageWithURL:[NSURL URLWithString:@"xx"]placeholderImage:niloptions:SDWebImageLowPriority | SDWebImageProgressiveLoad |SDWebImageRefreshCached |SDWebImageContinueInBackground];

options这里可以直接传入多个枚举值,可用于方法内部与或运算进行判断,方便传值;类似的还有UIControlState;

typedef NS_OPTIONS(NSUInteger, UIControlState) {UIControlStateNormal       = 0,UIControlStateHighlighted  = 1 << 0,                  // used when UIControl isHighlighted is setUIControlStateDisabled     = 1 << 1,UIControlStateSelected     = 1 << 2,                  // flag usable by app (see below)UIControlStateFocused API_AVAILABLE(ios(9.0)) = 1 << 3, // Applicable only when the screen supports focusUIControlStateApplication  = 0x00FF0000,              // additional flags available for application useUIControlStateReserved     = 0xFF000000               // flags reserved for internal framework use
};
[testBtn setTitle:@"xx"forState:UIControlStateNormal | UIControlStateHighlighted | UIControlStateSelected];
http://www.ritt.cn/news/2891.html

相关文章:

  • 案例较少如何做设计公司网站网络营销的效果是什么
  • 做鞋子的招聘网站有哪些软文写手接单平台
  • 互联网网站制作公司哪家好今日热点新闻10条
  • 网站建设高清图疫情排行榜最新消息
  • 网站主机免费seo投放营销
  • 有什么展厅设计做的好的网站友链交换平台源码
  • 做医疗的网站怎么线上推广自己的产品
  • 外国做家具的网站品牌营销推广
  • 深圳做网站企业360线上推广
  • 成安网站建设域名注册入口
  • 免费网站你会回来感谢我的seo运营
  • 建立一个商城网站seo培训网
  • 英文版wordpress主题开封搜索引擎优化
  • 常州公司网站建设免费营销软件网站
  • 公司网站怎么申请创建网站怎么创
  • 阳泉那有做网站的怎么可以让百度快速收录视频
  • 无锡做设计公司网站郑州seo代理商
  • 泰安公司做网站百度搜索指数查询
  • 上海通信管理局网站八八网
  • 网站首页动画模板网站改版
  • 阳江做网站公司推广拉新任务的平台
  • 代刷开通建设网站茶叶网络推广方案
  • 做网站要写代码吗网络营销的方法有哪些?
  • 做新闻类网站手机如何建网站
  • php网站开发工资多少钱优化大师下载
  • .net网站程序软文推广范文
  • 室内设计平面图分析北京seo优化分析
  • 网站首页做多大分辨率苏州网站建设优化
  • 施工企业为何不需要二级造价师青岛seo关键词优化排名
  • 某公司人事管理网站开发武汉seo全网营销