Given a NSString containing ISO 3166-1 alpha-2 two-letter country code as the only input, how can I output new NSString containing Emoji flag of the corresponding country, please?
Asked
Active
Viewed 1,411 times
1 Answers
1
+ (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]]];}

Piotr Farbiszewski
- 71
- 6
-
1Another solution was posted here: http://stackoverflow.com/a/34995291/1187415, it does not required a mapping dictionary. – Martin R Nov 24 '16 at 12:07