[swift-evolution] Proposal: weakStrong self in completion handler closures
Robert Vojta
rvojta at me.com
Sun Dec 6 03:30:11 CST 2015
> On 06 Dec 2015, at 09:19, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
>
> How would weakStrong work if the closure has a non-Void return type?
Allowed only for optional (closure) parameters?
doSmth(handler: (() -> Bool)?) { [weakStrong self] in
}
weakStrong makes sense for async only where self (or anything else) can disappear. It does not make sense for @noescape, ...
> Personally, I just use
>
> guard let this = self else { return }
>
> in this scenario. It's not much trouble to type `this.foo` instead of
> `self.foo` (it's even the same number of letters).
Way to do. But if you decide to move code outside the closure you're forced to replace this. with self. or delete this. The code shouldn't differ (this vs self vs strongSelf) if it's in the closure or outside of it.
Robert
More information about the swift-evolution
mailing list