列舉和字串的相互轉化
阿新 • • 發佈:2019-02-11
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])