标签:
在项目中使用不规则的字符串枚举 出现了问题 现采用OC与swift混编的模式提高编写效率 class SAMEnumsList:NSObject{ lazy var UpdateAtEnum:[[Int:String]] = { var dict = [[Int:String]](); dict.append([1:"最近1天更新"]) ;//In1Day dict.append([3:"最近3天"]) ;//In3Day dict.append([7:"最近7天"]) ;//In7Day dict.append([15:"最近15天"]) ;//In15Day dict.append([30:"最近30天"]) ;//In30Day return dict; }(); } objc_msgSend 报错 以下是解决方法 - - > typedef id(*sam_msgSend)(void *,SEL); - (void)getEnumName:(NSString *)enumName AllValues:(NSArray *__autoreleasing *)values keys:(NSArray *__autoreleasing *)keys { SAMEnumsList *enumList = [SAMEnumsList new]; SEL selector = NSSelectorFromString(enumName); sam_msgSend msg_send = (sam_msgSend)objc_msgSend; NSArray *arr = msg_send((__bridge void *)(enumList),selector); NSMutableArray *arrM_values = [NSMutableArray array]; NSMutableArray *arrM_keys = [NSMutableArray array]; for (NSInteger i = 0 ; i < arr.count ; ++i) { NSDictionary *dict = arr[i]; [arrM_keys addObject:[[dict allKeys] lastObject]]; [arrM_values addObject:[dict.allValues lastObject]]; } // 赋值 *values = [arrM_values copy]; *keys = [arrM_keys copy]; NSLog(@"%@",*values); NSLog(@"%@",*keys); }
标签:
原文地址:http://www.cnblogs.com/wolfman4secret/p/5051343.html