枚举和字符串的相互转化
2015-08-07 14:39
501 查看
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])
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])
相关文章推荐
- 要慎用mysql的enum字段的原因
- c++ 尽量不要使用#define 而是用const、enum、inline替换。
- mysql之set与enum的介绍
- iOS开发之路--微博“更多”页面
- Python中模拟enum枚举类型的5种方法分享
- Java枚举类enum介绍
- iOS开发之路--微博骨架搭建
- IOS开发代码分享之获取启动画面图片的string
- IOS开发之路--C语言数组和字符串
- IOS开发代码分享之用nstimer实现倒计时功能
- IOS开发代码分享之设置UISearchBar的背景颜色
- 一个运用enum类型的Demo
- enum实现单例模式
- ios开发之环境搭建-01
- 在开发iOS程序时对日期处理的总结
- iOS开发——keychain的使用
- iOS Graphics Technologies iOS 图形技术
- iOS开发异常错误总结
- enum VARENUM
- 学习Objective-C:入门手册