Last active
August 3, 2017 17:57
-
-
Save chris-hatton/3014e8ce4eda108a74c8 to your computer and use it in GitHub Desktop.
Swift Protocol Extension and Generics
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 | |
{ | |
typealias GenType | |
func doSomething(param: GenType) | |
} | |
class MyObject<T> : MyProtocol | |
{ | |
typealias GenType = T | |
var param : T { get } | |
func doSomething(param: GenType) | |
{ | |
print("Doing something with \(param)") | |
} | |
} | |
extension MyProtocol | |
{ | |
func doSomethingElse(param: GenType) // This line will not compile; GenType is unavailable here | |
{ | |
let param : GenType = self.param // How can we compile against type of self.param here? | |
print("Doing something else with \(param)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment