枚举与字符串映射
Posted 壮志凌云的博客园
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了枚举与字符串映射相关的知识,希望对你有一定的参考价值。
代码:
#import <Foundation/Foundation.h> typedef NS_ENUM(NSUInteger, NetworkStatus){ NetworkStatusGood = 0, NetworkStatusBad }; NSString * const NetworkStatusNameMapping[] = { [NetworkStatusGood] = @"NetworkStatusGood", [NetworkStatusBad] = @"NetworkStatusBad" }; int main(int argc, const char * argv[]) { @autoreleasepool { // 打印枚举值与其对应的字符串 NSLog(@"NetworkStatusGood = (%tu, %@)", NetworkStatusGood, NetworkStatusNameMapping[NetworkStatusGood]); NSLog(@"NetworkStatusBad = (%tu, %@)", NetworkStatusBad, NetworkStatusNameMapping[NetworkStatusBad]); } return 0; }
输出:
NetworkStatusGood = (0, NetworkStatusGood) NetworkStatusBad = (1, NetworkStatusBad)
以上是关于枚举与字符串映射的主要内容,如果未能解决你的问题,请参考以下文章
Angular:将字符串数组映射到http get调用中的枚举值数组