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

Robert Vojta rvojta at me.com
Sun Dec 6 01:46:18 CST 2015



> On 05 Dec 2015, at 22:36, Jacob Bandes-Storch <jtbandes at gmail.com> wrote:
> 
> When you use "weak self", self becomes Optional inside the closure, and indeed it *can* become nil partway through. This is the same as __weak in Objective-C, and there's actually a clang warning for it (search for "repeated-use-of-weak" or see http://devstreaming.apple.com/videos/wwdc/2013/404xbx2xvp1eaaqonr8zokm/404/404.pdf).

Yep, that's correct.

> That's why "guard let strongSelf = self" is important, and I think "guard let self = self" would add value without adding confusion.

Agree that weakStrong can be confusing and there's maybe better way to do it. But at least, "guard let self = self" would be enough and we can avoid ugly and long strongSel with it.

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/53b54f9c/attachment.html>


More information about the swift-evolution mailing list