Objective-C枚举,NS_ENUM和NS_OPTIONS

Objective-C枚举,NS_ENUM和NS_OPTIONS,第1张

概述在Objective-C中创建具有特定类型的枚举的正确方法是什么? NS_ENUM和NS_OPTIONS如何工作? NS_OPTIONS用于掩码,如NSAutoresizing?谢谢。 Code from NSObjCRuntime.h #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type 在Objective-C中创建具有特定类型的枚举的正确方法是什么? NS_ENUM和NS_OPTIONS如何工作? NS_OPTIONS用于掩码,如NSautoresizing?谢谢。

Code from NSObjCRuntime.h    #define NS_ENUM(_type,_name) enum _name : _type _name; enum _name : _type    #define NS_OPTIONS(_type,_name) _type _name; enum : _type
解决方法 例如从 NSHipster. NS_OPTIONS以类似的方式使用,但是对于通常是一个掩码的枚举

代替

typedef enum {    UItableVIEwCellStyleDefault,UItableVIEwCellStyleValue1,UItableVIEwCellStyleValue2,UItableVIEwCellStyleSubTitle} UItableVIEwCellStyle;

要么

typedef enum {    UItableVIEwCellStyleDefault,UItableVIEwCellStyleSubTitle};typedef NSInteger UItableVIEwCellStyle;

做这个:

typedef NS_ENUM(NSInteger,UItableVIEwCellStyle) {    UItableVIEwCellStyleDefault,UItableVIEwCellStyleSubTitle};

一个例子NS_OPTIONS枚举:

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};
总结

以上是内存溢出为你收集整理的Objective-C枚举,NS_ENUM和NS_OPTIONS全部内容,希望文章能够帮你解决Objective-C枚举,NS_ENUM和NS_OPTIONS所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1039247.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存