Created
October 2, 2019 14:45
-
-
Save BasThomas/ac38332eb88a7e095d69145bca58b513 to your computer and use it in GitHub Desktop.
This file contains 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 { | |
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