字符串与枚举相互转换

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])
posted @ 2016-11-09 16:41  浪人残风  阅读(519)  评论(0编辑  收藏  举报