Michael
Michael

Reputation: 1030

swift function calls: self-keyword vs without

I was wondering if there is any difference between those two a function-calls in a class:

self.myFuction()

VS

myFunction()

it is working in both ways. Is there the case where it's necessary to use the self-keyword?

Upvotes: 5

Views: 944

Answers (1)

Dániel Nagy
Dániel Nagy

Reputation: 12015

In most cases: there is absolutely no difference. But it's more "swiftish" if you omit "self". But there is a case, when you have to use self: in closure expressions.

But since Swift 1.2, with the @noescape parameter, you can omit "self" in closures as well.

Upvotes: 6

Related Questions