Created
September 20, 2019 09:50
-
-
Save asobolevsky/fc23d6a86b31cfb2fc8c62119e5fdf42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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