首页 > 移动平台 > 详细

iOS 开发-- enum与typeof enum用法

时间:2015-12-04 12:21:05      阅读:419      评论:0      收藏:0      [点我收藏+]

一, 两者的用法

  枚举类型定义用关键字enum标识,形式为:

enum标识符

{

  枚举数据表

};

enum用来定义一系列宏定义常量区别用,相当于一系列的#define ** **,当然它后面的标识符也可当作一个类型标识符。

typedef :typedef为C语言的关键字,作用是为一种数据类型定义一个新名字。这里的数据类型包括内部数据类型(int, char等)和自定义的数据类型(struct等)

enum是枚举类型,有了typedef的理解容易看出,typedef enum定义了枚举类型,类型变量取值在enum{}范围内取,在使用中二者无差别。

例如:

enum HorizontalTitleAlignment

{

    HorizontalTitleAlignmentLeft,

    HorizontalTitleAlignmentCenter,

    HorizontalTitleAlignmentRight

};

HorizontalTitleAlignmentCenter的值为2。

typedef enum则是用来定义一个数据类型,那么该类型的变量值只能在恶奴们定义的范围内取。

typedef enum {

    UIButtonTypeCustom = 0,           // no button type

    UIButtonTypeRoundedRect,          // rounded rect, flat white button, like in address card

    UIButtonTypeDetailDisclosure,

    UIButtonTypeInfoLight,

    UIButtonTypeInfoDark,

    UIButtonTypeContactAdd,

} UIButtonType;

那么UIButtonType表示一个类别,它的值只能是UIButtonTypeCustom...

iOS 开发-- enum与typeof enum用法

原文:http://www.cnblogs.com/wmx-rj/p/4997102.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!