Skip to content

Instantly share code, notes, and snippets.

@yunustek
Created October 7, 2018 16:50
Show Gist options
  • Save yunustek/1a754f33e3d07ac2b6065fd74bef8977 to your computer and use it in GitHub Desktop.
Save yunustek/1a754f33e3d07ac2b6065fd74bef8977 to your computer and use it in GitHub Desktop.
Derived Collection of Enum Cases:
enum CompassDirection: CaseIterable {
case north, south, east, west
}
print("There are \(CompassDirection.allCases.count) directions.")
// Prints "There are 4 directions."
let caseList = CompassDirection.allCases
.map({ "\($0)" })
.joined(separator: ", ")
// caseList == "north, south, east, west"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment