Skip to content

Instantly share code, notes, and snippets.

@JacobGinsparg
Created February 25, 2016 17:01
Show Gist options
  • Save JacobGinsparg/4a82a5b04193cc7e0f71 to your computer and use it in GitHub Desktop.
Save JacobGinsparg/4a82a5b04193cc7e0f71 to your computer and use it in GitHub Desktop.
Passing multiple enum types to the same function
import UIKit
import Foundation
protocol Animal {}
protocol EnumType {}
enum Dog: EnumType {
case Direwolf
case GrayWolf
case Labrador
case GoldenRetriever
}
enum Cat: EnumType {
case Tabby
case Tiger
case Alley
}
extension Cat: Animal {}
extension Dog: Animal {}
let tab = Cat.Tabby
let dire = Dog.Direwolf
func doSomething(anim: Animal) {
switch anim {
case is Cat:
print("I'm a cat")
break
case is Dog:
print("I'm a dog")
break
default:
break
}
}
doSomething(tab)
doSomething(dire)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment