我只想到两种方式定义的枚举
- typedef NS_ENUM(NSInteger, kType) {
- kTypeString = 0,
- kTypeNumber,
- kTypeArray,
- kTypeBool,
- };
复制代码
- -(NSString*) enumToString:(kType)type{
- NSString* enumStr = nil;
- switch (type) {
- case kTypeString:
- enumStr = @"kTypeString";
- break;
- case kTypeNumber:
- enumStr = @"kTypeNumber";
- break;
- case kTypeArray:
- enumStr = @"kTypeArray";
- break;
- case kTypeBool:
- enumStr = @"kTypeBool";
- break;
- default:
- break;
- }
- return enumStr;
- }
复制代码- -(NSDictionary*) enumDataSource{
- return @{@(kTypeString):@"kTypeString",
- @(kTypeNumber):@"kTypeNumber",
- @(kTypeArray):@"kTypeArray"
- @(kTypeBool):@"kTypeBool"};
- }
- -(NSString*) getEnumToStringFromDic:(kType)type{
- return [[self enumDataSource] objectForKey:@(type)];
- }
复制代码
|