[swift-evolution] [Proposal] Allow upgrading weak self to strong self by assignment

Kurt Werle kurt at circlew.org
Fri Feb 19 16:47:28 CST 2016


And to follow up on my own email, isn't that exactly the flow you want?

First you do
{ [unowned self]? in
  ...
}

Then you realize that you need to deal with the else case.  You nuke the ?
and add a guard.
{ [unowned self] in
  guard if unowned self != nil self {
    ...

I mean -- I look at that and it seems clear and easy.  You have the ? to
deal with the nil case.  You remove it and add the block to deal with the
special nil case.  The intention of both seems clear.  You added the guard
code when you needed it.

Sign me up!
Kurt

On Fri, Feb 19, 2016 at 2:39 PM, Kurt Werle <kurt at circlew.org> wrote:

>
>
> On Fri, Feb 19, 2016 at 2:30 PM, Shawn Erickson <shawnce at gmail.com> wrote:
>
>> I get that :) but I think it would be helpful to go beyond the no-op case
>> and help solve the "strongify" situation that exists in the larger problem
>> domain.
>>
>>>
> OK - so what's wrong with:
>
>
>> { [unowned self] in
>>>   guard self != nil else {
>>>     Do the other thing
>>>   }
>>> }
>>>
>>
> It's basically what you're asking for - an unowned implicitly unwrapped
> variable followed by an else statement that takes care of the nil case.
> Right?
>
> Kurt
> --
> kurt at CircleW.org
> http://www.CircleW.org/kurt/
>



-- 
kurt at CircleW.org
http://www.CircleW.org/kurt/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160219/2ead2dff/attachment.html>


More information about the swift-evolution mailing list