枚举和结构体

来源:互联网 发布:linux有几个版本 编辑:程序博客网 时间:2024/05/16 02:48

1.枚举类型

//推荐的定义枚举类型的方式typedef NS_ENUM(NSInteger, RWTLeftMenuTopItemType) {    RWTLeftMenuTopItemMain,    RWTLeftMenuTopItemShows,    RWTLeftMenuTopItemSchedule  };  typedef NS_ENUM(NSInteger, RWTGlobalConstants) {    RWTPinSizeMin = 1,    RWTPinSizeMax = 5,    RWTPinCountMin = 100,    RWTPinCountMax = 500,  };  //不推荐的方式enum GlobalConstants {    kMaxPinSize = 5,    kMaxPinCount = 500,  };  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

2.结构体


 //1.定义一个Sample结构体    struct Sample {        int a;        int b;        int c;    };    //初始化的时候,可以这样赋值    struct Sample sampleStruct = {1, 2, 1};    NSLog(@"sampleStruct中的值%d",sampleStruct.a );   //2 .定义一个Sample结构体    struct Sample{        int a;        int b;        int c;    }sampleStruct;    typedef struct Sample MySampleStruct;    //以后用这个结构体,就可以直接用MySampleStruct去定义了    MySampleStruct samDefineStructVarible = {1,2,1};    samDefineStructVarible.a = 1;    samDefineStructVarible.b =2;    samDefineStructVarible.c = 3;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

    0 0
    原创粉丝点击