枚举
2015-12-02 19:05
323 查看
一般情况下,我们采用C风格的enum关键字可以定义枚举类型。
枚举值一般是4个字节的int值,在64位系统上是8个字节。
在iOS6和Mac OS 10.8以后Apple引入了两个宏来重新定义这两个枚举类型,实际上是将enum定义和typedef合二为一,并且采用不同的宏来从代码角度来区分。
NS_OPTIONS一般用来定义位移相关操作的枚举值,我们可以参考UIKit.Framework的头文件,可以看到大量的枚举定义。
enum{ UIViewAnimationTransitionNone, UIViewAnimationTransitionFlipFromLeft, UIViewAnimationTransitionFlipFromRight, UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown, } UIViewAnimationTransition; //位移操作枚举定义 enum { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << 3, UIViewAutoresizingFlexibleHeight = 1 << 4, UIViewAutoresizingFlexibleBottomMargin = 1 << 5 }; typedef NSUInteger UIViewAutoresizing;//使用NSUInteger的地方可以使用UIViewAutoresizing,//UIViewAutoresizing相当于NSUInteger的一个别名使用。 //因此一个UIViewAutoresizing的变量可以直接赋值给NSUInteger
枚举值一般是4个字节的int值,在64位系统上是8个字节。
在iOS6和Mac OS 10.8以后Apple引入了两个宏来重新定义这两个枚举类型,实际上是将enum定义和typedef合二为一,并且采用不同的宏来从代码角度来区分。
NS_OPTIONS一般用来定义位移相关操作的枚举值,我们可以参考UIKit.Framework的头文件,可以看到大量的枚举定义。
typedef NS_ENUM(NSInteger, UIViewAnimationTransition) { UIViewAnimationTransitionNone,//默认从0开始 UIViewAnimationTransitionFlipFromLeft, UIViewAnimationTransitionFlipFromRight, UIViewAnimationTransitionCurlUp, UIViewAnimationTransitionCurlDown, }; typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) { UIViewAutoresizingNone = 0, UIViewAutoresizingFlexibleLeftMargin = 1 << 0, UIViewAutoresizingFlexibleWidth = 1 << 1, UIViewAutoresizingFlexibleRightMargin = 1 << 2, UIViewAutoresizingFlexibleTopMargin = 1 << 3, UIViewAutoresizingFlexibleHeight = 1 << 4, UIViewAutoresizingFlexibleBottomMargin = 1 << 5 };
#if (__cplusplus && __cplusplus >= 201103L && (__has_extension(cxx_strong_enums) || __has_feature(objc_fixed_enum))) || (!__cplusplus && __has_feature(objc_fixed_enum)) #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type #if (__cplusplus) #define NS_OPTIONS(_type, _name) _type _name; enum : _type #else #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type #endif #else #define NS_ENUM(_type, _name) _type _name; enum #define NS_OPTIONS(_type, _name) _type _name; enum #endif
相关文章推荐
- 它将被转换到一个函数来显示数据行以逗号分隔的数据列在一排
- MongoDB 文档的更新操作
- poj 3723 Conscription 并查集+Kruskal 求最小生成树
- Wee5-4PP attachment 3
- Web开发2015年十大趋势
- 数据结构——程序性能分析
- LinkedList,双向链表的实现
- 泛型操作范例
- 全功能智能车之再完善电路图(第十八篇)
- 用DEV做的,运行时程序停止
- 我对JS的理解
- jquery格式化时间,拼接DateTime时间
- 双目立体视觉系统精度分析
- fzu月赛(2015.11)
- oc中的copy与mutableCopy
- java中static和final关键字
- 机器学习维度灾难(二)
- 兄弟连新版ThinkPHP视频教程2.ThinkPHP 3.1.2 MVC模式和URL访问
- js入门(十)——原型
- java设计模式之单例模式