Skip to content

Instantly share code, notes, and snippets.

@Adobels
Created February 4, 2020 14:53
Show Gist options
  • Save Adobels/e2929df6b3855292b5e169c550ea7ee8 to your computer and use it in GitHub Desktop.
Save Adobels/e2929df6b3855292b5e169c550ea7ee8 to your computer and use it in GitHub Desktop.
//
// 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