Allowing `guard let self = self else { … }` for weakly captured self in a closure.


(Hoon H.) #1

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.


(Patrick Smith) #2

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@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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution