Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. protocol MyProtocol {
  2. func doThe(thing: String)
  3. }
  4.  
  5. extension MyProtocol {
  6. func doThe(thing: String = "") {
  7. print("protocol")
  8. }
  9. }
  10.  
  11. class MyImplementation: MyProtocol {
  12. func doThe(thing: String = "") {
  13. print("implementation")
  14. }
  15. }
  16.  
  17. class MyThing {
  18. let myProtocol: MyProtocol
  19. init(myProtocol: MyProtocol) {
  20. self.myProtocol = myProtocol
  21. }
  22.  
  23. func doTheThing() {
  24. myProtocol.doThe(thing: "") // prints "implementation"
  25. myProtocol.doThe() // prints "protocol"
  26. }
  27. }
  28.  
  29. MyThing(myProtocol: MyImplementation()).doTheThing()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement