字符串与枚举相互转换

时间:2021-05-04 17:54:41
enum DPodRecordType{ DPodRecordTypeA = 0,  DPodRecordTypeCNAME,  DPodRecordTypeMX,  DPodRecordTypeTXT,  DPodRecordTypeNS, 

DPodRecordTypeAAAA, DPodRecordTypeSRV, DPodRecordTypeURL }; typedef enum DPodRecordType DPodRecordType; const NSArray *___DPodRecordType; // 创建初始化函数。等于用宏创建一个getter函数 #define cDPodRecordTypeGet (___DPodRecordType == nil ? ___DPodRecordType = [[NSArray alloc] initWithObjects:\ @"A",\ @"CNAME",\ @"MX",\ @"TXT",\ @"NS",\ @"AAAA",\ @"SRV",\ @"URL", nil] : ___DPodRecordType) // 枚举 to 字串 #define cDPodRecordTypeString(type) ([cDPodRecordTypeGet objectAtIndex:type]) // 字串 to 枚举 #define cDPodRecordTypeEnum(string) ([cDPodRecordTypeGet indexOfObject:string])