Skip to content

Instantly share code, notes, and snippets.

@chris-hatton
Last active August 3, 2017 17:57
Show Gist options
  • Save chris-hatton/3014e8ce4eda108a74c8 to your computer and use it in GitHub Desktop.
Save chris-hatton/3014e8ce4eda108a74c8 to your computer and use it in GitHub Desktop.
Swift Protocol Extension and Generics
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