Created
September 5, 2016 19:15
-
-
Save PaulWoodIII/c84def3aaf204148bf81a4b67bb64497 to your computer and use it in GitHub Desktop.
Get all NSTimeZones and turn it into a usable Dictionary
This file contains hidden or 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
| //: # TimeZones | |
| import Foundation | |
| let tzs = NSTimeZone.knownTimeZoneNames() | |
| var seperated : [String:Array<String>] = [String:[String]]() | |
| func addToSeperated(_ region : String,_ place:String) -> Void { | |
| if let _ = seperated[region] { | |
| } | |
| else { | |
| seperated[region] = Array<String>() | |
| } | |
| seperated[region]!.append(place) | |
| print(seperated[region]!.count) | |
| } | |
| for string in tzs { | |
| let parsed = string.componentsSeparatedByString("/") | |
| print(parsed) | |
| guard parsed.count == 2 else { | |
| continue | |
| } | |
| let region = parsed[0] | |
| let specific = parsed[1] | |
| addToSeperated(region,specific) | |
| } | |
| print(seperated) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bad variable names like seperated, but hey it'll get you there!