Created
February 25, 2016 17:01
-
-
Save JacobGinsparg/4a82a5b04193cc7e0f71 to your computer and use it in GitHub Desktop.
Passing multiple enum types to the same function
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
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