枚举和字符串的相互转化



enum DPodRecordType{
    un_pay         = 0,
    un_ext_pay     = 1,
    has_pay        = 2,
    artisan_start  = 3,
    service_begin  = 4,
    service_finish = 5,
    cancel         = 6,
    order_finish   = 7,
    req_refund     = 8,
};
typedef enum DPodRecordType DPodRecordType;
const NSArray *___DPodRecordType;
// 创建初始化函数,等于用宏创建一个getter函数
#define cDPodRecordTypeGet (___DPodRecordType == nil ? ___DPodRecordType = [[NSArray alloc] initWithObjects:\
@"un_pay",\
@"un_ext_pay",\
@"has_pay",\
@"artisan_start",\
@"service_begin",\
@"service_finish",\
@"cancel",\
@"order_finish",\
@"req_refund", nil]:___DPodRecordType)

// 枚举 to 字串
#define cDPodRecordTypeString(type) ([cDPodRecordTypeGet objectAtIndex:type])
// 字串 to 枚举
#define cDPodRecordTypeEnum(string) ([cDPodRecordTypeGet indexOfObject:string])

你可能感兴趣的:(iOS,互联网,移动开发)