我注意到在Swift 2.2中,标记为非转义的闭包@noescape不需要显式self.在Swift 3中,默认情况下所有闭包都是非转义的,现在要求它们标记,@escaping如果你想让它们能够逃脱的话.
鉴于默认情况下Swift 3中的所有闭包都是非转义的,为什么它们需要显式self?
final class SomeViewController: NSViewController {
var someClosure: () -> () = { _ in }
override func viewDidLoad() {
super.viewDidLoad()
someClosure = {
view.layer = CALayer() // ERROR: Implicit use of `self` in closure; use `self.` to make capture semantics explicit
}
}
}
Run Code Online (Sandbox Code Playgroud)