Skip to content

Instantly share code, notes, and snippets.

@simme
Created February 8, 2019 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simme/0cd732a41e00b1962e6a40934fb2f702 to your computer and use it in GitHub Desktop.
Save simme/0cd732a41e00b1962e6a40934fb2f702 to your computer and use it in GitHub Desktop.
enum MySpecialEnum {
case someCase
case someCaseWithAssociatedData(String)
case someCaseWithNumbers(Int)
}
func handleSpecialEnum(_ value: MySpecialEnum) {
switch value {
case .someCase:
justDoSomething()
case let .someCaseWithAssociatedData(stringValue) where stringValue == "foo":
handleFoo()
case let .someCaseWithAssociatedData(stringValue):
handleAssociatedData(stringValue)
case let .someCaseWithNumbers(integerValue) where integerValue < 10:
handleSmallNumbers(integerValue)
case let .someCaseWithNumbers(integerValue):
handleBigNumbers(integerValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment