Created
October 22, 2014 22:46
-
-
Save wjlafrance/2ed930fc69e089d3a1b2 to your computer and use it in GitHub Desktop.
Generic where type is constrained by class and protocol
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
protocol MyProtocol { | |
func methodFromProtocol() | |
} | |
class MyClass { | |
func methodFromClass() { | |
println("hello class") | |
} | |
} | |
class MyClassImplementingMyProtocol : MyClass, MyProtocol { | |
func methodFromProtocol() { | |
println("hello protocol") | |
} | |
} | |
func doThing<T: MyClass where T: MyProtocol>(myThing: T) { | |
myThing.methodFromProtocol() | |
myThing.methodFromClass() | |
} | |
doThing(MyClassImplementingMyProtocol()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment