2016-11-24 162 views
0

表情符号给定一个包含ISO 3166-1 alpha-2双字母国家代码作为唯一输入的NSString,如何输出新的NSString包含相应国家的表情符号标志?ISO国家代码

回答

0
+ (NSString*_Nullable) emojiFromCountryCode: (NSString*_Nonnull) countryCode { 

/* https://en.wikipedia.org/wiki/Regional_Indicator_Symbol 

The regional indicator symbols are a set of 26 alphabetic Unicode characters (A-Z) intended to be used to encode ISO 3166-1 alpha-2 two-letter country codes in a way that allows optional special treatment. 
These were defined as part of the Unicode 6.0 support for emoji, as an alternative to encoding separate characters for each country flag. Although they can be displayed as Roman letters, it is intended that implementations may choose to display them in other ways, such as by using national flags.[1][2] The Unicode FAQ indicates that this mechanism should be used and that symbols for national flags will not be directly encoded.[3] 
They are encoded in the range U+1F1E6 REGIONAL INDICATOR SYMBOL LETTER A (HTML 🇦) to U+1F1FF REGIONAL INDICATOR SYMBOL LETTER Z (HTML 🇿) within the Enclosed Alphanumeric Supplement block in the Supplementary Multilingual Plane.[4] 

*/ 

NSDictionary* map = @{ @"A" : @"", 
         @"B" : @"", 
         @"C" : @"", 
         @"D" : @"", 
         @"E" : @"", 
         @"F" : @"", 
         @"G" : @"", 
         @"H" : @"", 
         @"I" : @"", 
         @"J" : @"", 
         @"K" : @"", 
         @"L" : @"", 
         @"M" : @"", 
         @"N" : @"", 
         @"O" : @"", 
         @"P" : @"", 
         @"Q" : @"", 
         @"R" : @"", 
         @"S" : @"", 
         @"T" : @"", 
         @"U" : @"", 
         @"V" : @"", 
         @"W" : @"", 
         @"X" : @"", 
         @"Y" : @"", 
         @"Z" : @"" 
         }; 

//TRY 
return [[map valueForKey: [countryCode substringToIndex: 1]] stringByAppendingString: [map valueForKey: [countryCode substringFromIndex: 1]]];} 
+0

另一个解决方案发布在这里:http://stackoverflow.com/a/34995291/1187415,它不需要映射字典。 –