Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
List all iOS timezones
class TimeZoneManager {
static let shared = TimeZoneManager()
private init() {}
private var continents = [String]()
private var timeZonesList = [String: [String]]()
var timeZones: [String: [String]] {
get {
for timeZone in TimeZone.knownTimeZoneIdentifiers {
let continent = timeZone.components(separatedBy: "/")[0]
if !continents.contains(continent) {
continents.append(continent)
}
var timeZonesInContinent = timeZonesList[continent] ?? [String]()
if let zone = timeZone.components(separatedBy: "/").last {
if !timeZonesInContinent.contains(zone) {
timeZonesInContinent.append(zone)
}
}
timeZonesList[continent] = timeZonesInContinent
}
return timeZonesList
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment