Swiftly convert country codes and other unique strings to emoji flags
let usa = "us".flag() // "🇺🇸"
let england = "gb-eng".flag() // "🏴"
let un = "un".flag() // "🇺🇳"
let chequered = "chequered".flag() // "🏁"
Check out the Veximoji-Example
iOS app.
Simply follow standard SPM conventions:
- Add
package(url: "https://github.com/roz0n/Veximoji.git", from: "2.0.0")
to your application'sPackage.swift
file.
- Open your project within Xcode and select
File > Swift Packages > Add Package Dependency
from the status bar menu. - Paste the HTTPS Github link:
https://github.com/roz0n/Veximoji.git
and clickNext
. - You'll be asked to define package options.
Up to Next Major
is a safe default which accepts any version up to the next major release, clickNext
to proceed.
Once the package finishes downloading, should now see it listed in the Project Navigator on the left-hand pane. Likewise, feel free to select the project file, and Veximoji
should be listed under the Swift Packages
tab. Xcode will also automatically add it to your main project target under the "Frameworks, Libraries, and Embedded Content" header.
CocoaPods support is in the works.
The Veximoji
API is very concise and well-documented. It organizes emoji flags into four distinct categories:
Category | Definition | Example |
---|---|---|
country |
flags for countries with an ISO 3611-1 alpha-2 code | JP |
subdivision |
flags for subdivisions with an ISO 3611-2 code | GB-ENG |
international |
flags for exceptionally reserved ISO 3166-1 alpha-2 codes | EU or UN |
unique |
flags not related to individual countries or subdivisions | .pirate or "pirate" |
Each of the above categories are available in array-form via publicly exposed short-hand variables:
- A typealias of
Veximoji.FlagCategories
, an enum representing the above categories.
- Computes and returns all supported ISO 3166-1 country codes.
- Computes and returns all supported ISO 3166-2 subdivision codes.
- Computes and returns all supported exceptionally reserved ISO 3166-1 codes.
- Converts any string to its emoji flag counterpart if the string exists within a
FlagCategory
.
- Used to render a country's emoji flag by its ISO 3611-1 alpha-2 code
- Used to render a given subdivision’s emoji flag by its ISO 3611-2 code
Code | Flag |
---|---|
GB-ENG |
🏴 |
GB-SCT |
🏴 |
GB-WLS |
🏴 |
- Used to render the flag of an exceptionally reserved ISO 3166-1 alpha-2 code
Code | Flag |
---|---|
EU |
🇪🇺 |
UN |
🇺🇳 |
- Refers to an emoji flag that do not correspond to a country, region, or government entity. For example,
.pride
or"pride"
refers to the rainbow or pride flag.
Case | Raw value | Flag |
---|---|---|
.pride |
“pride” |
🏳️🌈 |
.trans |
“trans” |
🏳️⚧️ |
.pirate |
“pirate” |
🏴☠️ |
.white |
“white” |
🏳️ |
.red |
“red” |
🚩 |
.black |
“black” |
🏴 |
.crossed |
“crossed” |
🎌 |
.chequered |
“chequered” |
🏁 |
In the event you would like to validate any of the above manually, validation methods are publicly exposed for your convenience.
- Returns a boolean indicating whether a given string is a supported ISO 3611 alpha-2 country code by checking whether or not it is contained within the
CFLocaleCopyISOCountryCodes
collection - For more information on supported country codes visit the CFLocaleCopyISOCountryCodes page of the Apple Developer Documentation
- Returns a boolean indicating whether a given string is a valid ISO 3611-2 subdivision code
- Currently, only Great Britain’s subdivision codes are supported as they are the only subdivisions with iOS-supported emoji flags
- Returns a boolean indicating whether a given string is a valid ISO 3166-1 exceptionally reserved code.
- Currently, only
"EU"
and"UN"
exceptionally reserved codes are supported as they are the only codes with iOS-supported emoji flags
Email me at: arnold@rozon.org
MIT