[swift-evolution] [Draft Proposal] A simplified notation for avoiding the weak/strong dance with closure capture lists

Jason Gregori jasongregori at gmail.com
Fri Feb 12 16:20:41 CST 2016


Ah, I see. I think that totally makes sense but I would prefer to have just
one bit to write and not have to do both the [weak self] and the guard
statement.

This is why I keep coming back to [guard weak self]. I want to to make self
weak and I want to guard against it being nil.

On Fri, Feb 12, 2016 at 1:31 PM, Erica Sadun <erica at ericasadun.com> wrote:

> It would follow
>
> [weak self]
>
> not replace it, e.g.
>
> [weak self]
> guard reconstitute self else { return }
>
> I thought it might be handy to control how the guard exits scope,
> enabling self == nil (as well as any other reconstitutions of a weak
> variable) failure cases to do reporting, fatalError-ing, etc.
>
> -- E
>
>
> On Feb 12, 2016, at 12:08 PM, Jason Gregori <jasongregori at gmail.com>
> wrote:
>
>
>
> On Fri, Feb 12, 2016 at 10:34 AM, Erica Sadun <erica at ericasadun.com>
> wrote:
>
>> How about
>>
>> guard reconstitute self else { return }
>>
>
> I like the idea behind this but I feel like a line inside the block can't
> really dictate whether self is captured weakly or not. Unless your saying
> put this in the bracket part?
>
> [guard reconstitute self] ? That works for me.
>
>
> PS: I got here from your blog post, thanks!
>
>
>> -- E
>>
>> On Feb 12, 2016, at 11:28 AM, Jason Gregori via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>> I like Kenny and Kurt's points about handling the majority case and
>> keeping the syntax simpler.
>>
>> I feel like most of the time I want to break a retain cycle is for a
>> completion block which returns void. Can we just handle that case and get
>> rid of the else?
>>
>> Also, I don't think [guard self] is self explanatory enough. I think weak
>> should be in there so it's much more obvious you are doing the weak/strong
>> dance with self, otherwise it looks like you are guarding against a regular
>> optional being nil.
>>
>> So:
>>
>> [guard weak self, other]
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160212/c1991643/attachment.html>


More information about the swift-evolution mailing list