Last active
December 22, 2015 05:24
-
-
Save hachinobu/f7db9a840ef9d14ae3c8 to your computer and use it in GitHub Desktop.
Protocol Type generic
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 { | |
var myName: String { get } | |
init() | |
} | |
struct MyA: MyProtocol { | |
var myName: String { | |
return "My Name is A" | |
} | |
} | |
struct MyB: MyProtocol { | |
var myName: String { | |
return "My Name is B" | |
} | |
} | |
func printMy<T: MyProtocol>(my: T.Type) { | |
let my = T() | |
print(my.myName) | |
} | |
func printInitT<T: MyProtocol>(my: T) { | |
print(my.myName) | |
} | |
printMy(MyA.self) | |
printMy(MyB.self) | |
printInitT(MyA()) | |
printInitT(MyB()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment