Created
December 29, 2019 04:25
-
-
Save benbahrenburg/ffccf867e3924f447c6af4278db7efc6 to your computer and use it in GitHub Desktop.
List all iOS timezones
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
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