Last active
March 13, 2017 15:29
-
-
Save hborders/04ec58281c42241797e97c78e23cfa0c to your computer and use it in GitHub Desktop.
A simple Swift enum example
This file contains hidden or 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 Example { | |
case Foo(f: String, g: String) | |
case Bar(b: Int, c: Int) | |
} | |
func printExample(_ example: Example) { | |
switch example { | |
case .Foo(let f, let g): | |
print("Foo: \(f), \(g)") | |
case .Bar(let b, let c): | |
print("Bar: \(b), \(c)"); | |
} | |
} | |
let fooExample = Example.Foo(f: "foo", g: "goo") | |
let barExample = Example.Bar(b: 2, c: 3) | |
printExample(fooExample) // Foo: foo, goo | |
printExample(barExample) // Bar: 2, 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment