2016-11-24 5 views
0

Учитывая, что в качестве единственного входа используется NSString, содержащий двухбуквенный код страны ISO 3166-1 alpha-2, как я могу выводить новый NSString, содержащий флаг Emoji соответствующей страны, пожалуйста?Emoji из кода страны 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, для него не требуется словарь сопоставления. –

Смежные вопросы