[swift-evolution] [Proposal] Allow using optional binding to upgrade self from a weak to strong reference

Shawn Erickson shawnce at gmail.com
Sat Feb 20 01:03:26 CST 2016

True, however only if unowned works in terms of the desired object life
time / "ownership" for self. It isn't always sufficient so weak is needed
to avoid the retain cycle while safely supporting self becoming nil (e.g.
allowing the object referenced by self to go away while the block may still
be outstanding). The proposal outlines at least one example of that need
and is written assuming you need to use weak.
On Fri, Feb 19, 2016 at 10:15 PM Kurt Werle <kurt at circlew.org> wrote:

> On Fri, Feb 19, 2016 at 9:04 PM, Evan Maloney <emaloney at gilt.com> wrote:
> ...
>> With this feature, the code above could be rewritten as:
>> networkRequest.fetchData() { [weak self] result in
>>     guard let self = self else { return }
>> If you're going to have boilerplate like that, then the following seems
> like it accomplishes the same thing [in this specific case] without
> changing anything:
> networkRequest.fetchData() { [unowned self] result in
>>     guard self != nil else { return }
> 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/20160220/ed2b8d3b/attachment.html>

More information about the swift-evolution mailing list