Instantly share code, notes, and snippets.

What would you like to do?
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