Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement