[swift-evolution] Proposal: weakStrong self in completion handler closures

Robert Vojta rvojta at me.com
Sun Dec 6 05:20:51 CST 2015


> On 6. 12. 2015, at 11:01, Davide De Franceschi via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Most of the times you just want to `guard let strongSelf = self else { return }`, but that works when you return `Void` and you don't want to manage this "failure" in any other way...
> Should `weak-strong` be allowed only for closures that `-> Void`?

Can be and result will be optional. But it complicates things and makes it unclear. Which is not good.

> What if you want to fire a "completionBlock" anyway?

Then don't use weakStrong and use weak strong dance.

> While the need to remove this common boilerplate feels strong, I'm not certain this would be the right way. Can't really suggest a better alternative though.

Agree with you. I just wanted to start discussion about it, but not convinced about weakStrong as well.

Probably what Jacob proposed would be enough. Just allow "guard let self = self ..." at least to remove strongSelf, this, ...

Robert


More information about the swift-evolution mailing list