swift函数调用:自我关键字vs无 [英] swift function calls: self-keyword vs without
问题描述
$ b
self.myFuction() 我想知道这两个函数在类中是否有区别。 )
VS
myFunction()
它正在以两种方式工作。是否有必要使用self-keyword?
在大多数情况下:绝对没有区别。但是如果你省略自我,则更加快速。
但是有一种情况,当你必须在闭包表达式中使用self时:
但自从Swift 1.2开始,使用@noescape参数,您可以在关闭中省略self。 I was wondering if there is any difference between those two a function-calls in a class: VS it is working in both ways. Is there the case where it's necessary to use the self-keyword? 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. 这篇关于swift函数调用:自我关键字vs无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!self.myFuction()
myFunction()