SE-0365: Allow implicit self for weak self captures, after self is unwrapped

What is your evaluation of the proposal?

Strongly agreed, as written.
Its intention is very clear, and robust.

Is the problem being addressed significant enough to warrant a change to Swift?

Yes. It makes codes much cleaner.

Moreover it is not just a yet another sugar if I understand correctly.
It solves a common pitfall* at last, by cleverly following SE0269.

button.tapHandler = { [weak self] in
    guard let self else { return }

    execute {
        // error: call to method 'method' in closure requires 
        // explicit use of 'self' to make capture semantics explicit
        dismiss()
    }
}

If you follow the rule – capture self as weak then unwrap and use it implicitly – compiler assists you to determine if self has to be captured again in inner closures.

* Michael Tsai - Blog - Weak Self: Closure Rules of Thumb
* Weak Self -- Closure Rules of Thumb • Christian Tietze


Does this proposal fit well with the feel and direction of Swift?

Definitely. It feels very natural to have this.

If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

N/A

How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Read the proposal. And wanted this since its pitch along with SE-0345: Allow implicit `self` for `weak self` captures, after `self` is unwrapped

And thank you for the proposal!

1 Like