• iOS 开发-- enum与typeof enum用法


    一, 两者的用法

      枚举类型定义用关键字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...

  • 相关阅读:
    面向对象优势
    二维码
    数据库分页
    DBUtil连接数据库
    sqliteDOC创建数据库
    ajax的回调函数
    多线程
    JSTL优点
    WebSocket 搭建简单聊天网站
    全等和不全等
  • 原文地址:https://www.cnblogs.com/wmx-rj/p/4997102.html
Copyright © 2020-2023  润新知