60.枚举的创建和使用

1. 定义枚举

#import <UIKit/UIKit.h>

typedef enum

{

    //以下是枚举成员

    TestA = 0,

    TestB = 1,

    TestC = 2,

    TestD = 3

    

}TestType;//枚举名称

//枚举第二种写法

typedef NS_ENUM(NSInteger ,Test)

{

    

    Test1 = 0,

    test2 = 1,

    Test3 = 2,

    Test4 = 3

};

@interface ViewController : UIViewController

2.定义枚举属性

@property(nonatomic,assign)TestType type;

3.使用枚举

- (void)viewDidLoad {

    [super viewDidLoad];

    NSLog(@"%d%d%d%d",TestA,TestB,TestC,TestD);

    if (self.type == 0) {

        NSLog(@"我很好");

    }

}

原文地址:https://www.cnblogs.com/qiangzheVSruozhe/p/9402225.html