Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. class Dog {
  2. var name = ""
  3. var whatADogSays = "woof"
  4. func bark() {
  5. print(self.whatADogSays)
  6. }
  7. }
  8.  
  9. // you can omit the word self here
  10.  
  11. class Dog {
  12. var name = ""
  13. var whatADogSays = "woof"
  14. func bark() {
  15. print(whatADogSays)
  16. }
  17. func speak() {
  18. bark()
  19. }
  20. }
  21.  
  22. // reason is that if you omit the message recipient and the message you’re sending can be sent to self, the compiler supplies self as the message’s recipient under the hood.
  23. // it is best not to do that as matter of style
  24. // it is best to be explicit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement