Skip to content

Instantly share code, notes, and snippets.

@kevinpet
Created September 12, 2014 22:45
Show Gist options
  • Save kevinpet/0f4513e13efdc3a55c9e to your computer and use it in GitHub Desktop.
Save kevinpet/0f4513e13efdc3a55c9e to your computer and use it in GitHub Desktop.
Enum pattern matching in swift
enum Foo {
case Bar(bar: Int)
case Baz(baz: String)
}
func handle(f: Foo) -> Any {
switch f {
case .Bar(let bar):
return bar
case .Baz(let baz):
return baz
}
}
handle(.Bar(bar: 42))
handle(.Baz(baz: "Luhrmann"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment