iOS枚举

作者: 风轻鱼蛋 | 来源:发表于2017-09-14 09:58 被阅读0次

    一、简单介绍

    枚举是C语言中的一种基本数据类型,是一个"被命名的整型常量"的集合,它不参与内存的占用和释放,我们在开发中使用枚举的目的只有一个,那就是为了增加代码的可读性

    二、实现方式

    1、C语言实现

    typedef enum {
        TextEnumTypeParame1,
        TextEnumTypeParame2,
        TextEnumTypeParame3,
    }TextEnumType;
    

    2、OC语言实现

    typedef NS_ENUM(NSUInteger, TextEnumType) {
        TextEnumTypeParame1,
        TextEnumTypeParame2,
        TextEnumTypeParame3,
    };
    

    3、位移枚举实现

    typedef NS_OPTIONS(NSUInteger, TextEnumType) {
        TextEnumTypeParame1 = 1<<0,
        TextEnumTypeParame2 = 1<<1,
        TextEnumTypeParame3 = 1<<2,
        TextEnumTypeParame4 = 1<<3,
        TextEnumTypeParame5 = 1<<4,
    };
    

    相关文章

      网友评论

          本文标题:iOS枚举

          本文链接:https://www.haomeiwen.com/subject/furlsxtx.html