swift function calls: self-keyword vs without

左心房为你撑大大i 提交于 2019-12-12 15:07:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/28675146/swift-function-calls-self-keyword-vs-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!