Created
February 4, 2020 14:53
-
-
Save Adobels/e2929df6b3855292b5e169c550ea7ee8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// EmojiFlag.swift | |
// | |
// Created by Blazej SLEBODA on 04/02/2020. | |
// | |
import Foundation | |
class EmojiFlag { | |
let unicodeDictionary: [String:String] = { | |
let dic = ["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":"๐ฟ"] | |
return dic | |
}() | |
func unicodeCodeForIso31661Alpha2(code: String) -> String { | |
let emptyReturn = "" | |
guard code.count == 2 else { | |
return emptyReturn | |
} | |
let firstLetter = String(code.first!) | |
let secondLetter = String(code.last!) | |
guard | |
let firstUnicode = unicodeDictionary[firstLetter], | |
let secondUnicode = unicodeDictionary[secondLetter] | |
else { | |
return emptyReturn | |
} | |
let unicode = String(format: "%@%@", firstUnicode, secondUnicode) | |
return unicode | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment