Skip to content

Instantly share code, notes, and snippets.

@asobolevsky
Created September 20, 2019 09:50
Show Gist options
  • Save asobolevsky/fc23d6a86b31cfb2fc8c62119e5fdf42 to your computer and use it in GitHub Desktop.
Save asobolevsky/fc23d6a86b31cfb2fc8c62119e5fdf42 to your computer and use it in GitHub Desktop.
enum CountryCode: String {
case us = "USA"
case zh = "China"
case fr = "France"
case ru = "Russia"
var locale: Locale {
let identifier: String
switch self {
case .us: identifier = "en_US"
case .zh: identifier = "zh_CN"
case .fr: identifier = "fr"
case .ru: identifier = "ru_RU"
}
return Locale(identifier: identifier)
}
}
func changeLocation() {
guard let title = countries.titleForSegment(at: countries.selectedSegmentIndex),
let country = CountryCode(rawValue: title) else {
return
}
convert(country.locale)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment