Skip to content

Instantly share code, notes, and snippets.

@BasThomas
Created October 2, 2019 14:45
Embed
What would you like to do?
protocol MyProtocol {
func doThe(thing: String)
}
extension MyProtocol {
func doThe(thing: String = "") {
print("protocol")
}
}
class MyImplementation: MyProtocol {
func doThe(thing: String = "") {
print("implementation")
}
}
class MyThing {
let myProtocol: MyProtocol
init(myProtocol: MyProtocol) {
self.myProtocol = myProtocol
}
func doTheThing() {
myProtocol.doThe(thing: "") // prints "implementation"
myProtocol.doThe() // prints "protocol"
}
}
MyThing(myProtocol: MyImplementation()).doTheThing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment