Contents

andreabusi/SwiftFlags

Get emoji flag from a country name or country code (ISO 3166-1)

Usage

SwiftFlags comes with some static methods that you can use:

class func flag(for country: String) -> String?
class func countryCode(for country: String) -> String?

Examples

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")

Requirements

The latest version of SwiftFlags require:

  • Swift 5
  • XCode 11+ (in order to use Swift Package Manager)

Installation

SwiftFlags is available via Swift Package Manager or you can directly embeed the library inside your project.

Swift Package Manager

Add the repo URL using the Swift Package Manager built inside Xcode:

https://github.com/andreabusi/SwiftFlags.git

Manual installation

Just drag and drop the files under the Sources folder inside your project.

Credits

This library is based on the work of two existing library:

Thanks guys for your work!

ToDo

  • [x] Add Swift Package Manager support
  • [x] Improve ObjC interoperability

Package Metadata

Repository: andreabusi/SwiftFlags

Stars: 13

Forks: 0

Open issues: 0

Default branch: master

Primary language: swift

License: MIT

README: README.md