-3

As you can see in the screen below, iOS Calendar app shows the list of available time zone in City, Country format.

enter image description here

I want to attain the same list. Where can I get this list?

Ham Dong Kyun
  • 756
  • 4
  • 28

2 Answers2

1

You cannot get a "City, County" format, but you can get a "City, Continent" format using this piece of code:

let timeZones = TimeZone.knownTimeZoneIdentifiers.flatMap{ id->String? in
    let components = id.components(separatedBy: "/")
    guard components.count == 2, let continent = components.first, let city = components.last else {return nil}
    return "\(city), \(continent)"
}

Output will be:

"Abidjan, Africa", "Accra, Africa", "Addis_Ababa, Africa", "Algiers, Africa", "Asmara, Africa", "Bamako, Africa", "Bangui, Africa", "Banjul, Africa"...

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
0

TimeZone has a static function knownTimeZoneIdentifiers which returns an array of String identifiers. Documentation

Dima
  • 23,484
  • 6
  • 56
  • 83