Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dog {
- var name = ""
- var whatADogSays = "woof"
- func bark() {
- print(self.whatADogSays)
- }
- }
- // you can omit the word self here
- class Dog {
- var name = ""
- var whatADogSays = "woof"
- func bark() {
- print(whatADogSays)
- }
- func speak() {
- bark()
- }
- }
- // 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.
- // it is best not to do that as matter of style
- // it is best to be explicit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement