SwiftFlags is a simple library to get emoji flag from a country name or a country code (ISO 3166-1).
SwiftFlags comes with some static methods that you can use:
class func flag(for country: String) -> String?class func countryCode(for country: String) -> String?Here are some examples to get the emoji flag for a country. You can pass both a country name or a country code:
// Returns 🇮🇹
let _ = SwiftFlags.flag(for: "italy")
// Returns 🇺🇸
let _ = SwiftFlags.flag(for: "United States")
// Returns nil
let _ = SwiftFlags.flag(for: "England")
// Returns 🇯🇵
let _ = SwiftFlags.flag(for: "JP")
// Returns 🇰🇷
let _ = SwiftFlags.flag(for: "Korea, South")SwiftFlags also provide the ability to return the ISO country code for a given country:
// Returns 'IT'
let _ = SwiftFlags.countryCode(for: "italy")
// Returns 'US'
let _ = SwiftFlags.countryCode(for: "United States")
// Returns nil
let _ = SwiftFlags.countryCode(for: "England")The latest version of SwiftFlags require:
- Swift 5
- XCode 11+ (in order to use Swift Package Manager)
SwiftFlags is available via Swift Package Manager or you can directly embeed the library inside your project.
Add the repo URL using the Swift Package Manager built inside Xcode:
https://github.com/andreabusi/SwiftFlags.git
Just drag and drop the files under the Sources folder inside your project.
This library is based on the work of two existing library:
- country-emoji, available for JavaScript
- flag-emoji-from-country-code, a great snippet to get the emoji flag from an ISO 3166-1 region code
Thanks guys for your work!
- Add Swift Package Manager support
- Improve ObjC interoperability