[swift-evolution] Allowing `guard let self = self else { … }` for weakly captured self in a closure.

Patrick Smith pgwsmith at gmail.com
Thu May 12 23:30:25 CDT 2016


How about [weak(guard) self]? It would only work with closures returning -> () as if you are weakly capturing something you are likely to be messaging that not returning some, so they can be ignored.

networkRequest.fetchData() { [weak(guard) self] result in
    switch result {
    case .succeeded(let data):
        self.processData(data)

    case .failed(let err):
        self.handleError(err)
    }
}

Patrick


> On 13 May 2016, at 2:10 AM, Hoon H. via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I am replying months lately, but anyway, I just read your proposal, and I think this is cool.
> 
>    [guard self]
> 
> I am in doubt about another stuffs such as `[guard self else …]`. I hope your proposal to be accepted. I am getting a bit tired of writing `guard let S = self else { … }`.
> 
> I am still not sure how to use mailing list… but I hope this to be a correct way.
> …Sending again because I mistyped Evan’s address.
> 
> — Hoon H.
> 
> _______________________________________________
> 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/20160513/da50157e/attachment.html>


More information about the swift-evolution mailing list