Created
September 12, 2014 22:45
-
-
Save kevinpet/0f4513e13efdc3a55c9e to your computer and use it in GitHub Desktop.
Enum pattern matching in swift
This file contains 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
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