Skip to content

Instantly share code, notes, and snippets.

@hborders
Last active March 13, 2017 15:29
Show Gist options
  • Save hborders/04ec58281c42241797e97c78e23cfa0c to your computer and use it in GitHub Desktop.
Save hborders/04ec58281c42241797e97c78e23cfa0c to your computer and use it in GitHub Desktop.
A simple Swift enum example
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