roz0n/veximoji
Swiftly convert country codes and other unique strings to emoji flags
Demo
Check out the Veximoji-Example iOS app.
Installation
Simply follow standard SPM conventions:
Swift Package Manager
Manual Installation
- Add
package(url: "https://github.com/roz0n/Veximoji.git", from: "2.0.0")to your application'sPackage.swiftfile.
Via Xcode
- Open your project within Xcode and select
File > Swift Packages > Add Package Dependencyfrom the status bar menu. - Paste the HTTPS Github link:
https://github.com/roz0n/Veximoji.gitand clickNext. - You'll be asked to define package options.
Up to Next Majoris a safe default which accepts any version up to the next major release, clickNextto 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
CocoaPods support is in the works.
API
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" |
Categories
Each of the above categories are available in array-form via publicly exposed short-hand variables:
typealias EmojiFlagCategory
- A typealias of
Veximoji.FlagCategories, an enum representing the above categories.
EmojiFlagCountryCodes: [String]
- Computes and returns all supported ISO 3166-1 country codes.
EmojiFlagSubdivisionCodes: [String]
- Computes and returns all supported ISO 3166-2 subdivision codes.
EmojiFlagInternationalCodes: [String]
- Computes and returns all supported exceptionally reserved ISO 3166-1 codes.
Helpers
String.flag(term:) -> String?
- Converts any string to its emoji flag counterpart if the string exists within a
FlagCategory.
country(code:) -> String?
- Used to render a country's emoji flag by its ISO 3611-1 alpha-2 code
subdivision(code:) -> String?
- Used to render a given subdivision’s emoji flag by its ISO 3611-2 code
Supported Codes
| Code | Flag | | :------- | :--- | | GB-ENG | 🏴 | | GB-SCT | 🏴 | | GB-WLS | 🏴 |
international(code:) -> String?
- Used to render the flag of an exceptionally reserved ISO 3166-1 alpha-2 code
Supported Codes
| Code | Flag | | :--- | :--- | | EU | 🇪🇺 | | UN | 🇺🇳 |
unique(term:) -> String?
- Refers to an emoji flag that do not correspond to a country, region, or government entity. For example,
.prideor"pride"refers to the rainbow or pride flag.
Supported Cases
| Case | Raw value | Flag | | :----------- | :------------ | :--- | | .pride | “pride” | 🏳️🌈 | | .trans | “trans” | 🏳️⚧️ | | .pirate | “pirate” | 🏴☠️ | | .white | “white” | 🏳️ | | .red | “red” | 🚩 | | .black | “black” | 🏴 | | .crossed | “crossed” | 🎌 | | .chequered | “chequered” | 🏁 |
Validators
In the event you would like to validate any of the above manually, validation methods are publicly exposed for your convenience.
validateISO3166_1(code:) -> Bool
- 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
CFLocaleCopyISOCountryCodescollection - For more information on supported country codes visit the CFLocaleCopyISOCountryCodes page of the Apple Developer Documentation
validateISO3166_2(code:) -> Bool
- 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
validateExceptionalReservation(code:) -> Bool
- 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
Support
Email me at: arnold@rozon.org
License
MIT
Package Metadata
Repository: roz0n/veximoji
Default branch: main
README: README.md