Skip to content

Instantly share code, notes, and snippets.

@BasThomas
Created October 2, 2019 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BasThomas/ac38332eb88a7e095d69145bca58b513 to your computer and use it in GitHub Desktop.
Save BasThomas/ac38332eb88a7e095d69145bca58b513 to your computer and use it in GitHub Desktop.
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