SwiftFormat icon indicating copy to clipboard operation
SwiftFormat copied to clipboard

Don't have implicit self for weak self captures, after self is unwrapped

Open yagiztw opened this issue 2 years ago • 1 comments

Implicit self is now permitted for weak self captures, after self is unwrapped. For example:

class ViewController {
  let button: Button

  func setup() {
      button.tapHandler = { [weak self] in
          guard let self else { return }
          dismiss() // refers to `self.dismiss()`
      }
  }

  func dismiss() { ... }
}

I looked into existing rules but couldn't find a rule that would allow us to force having explicit self. It would great if we have a rule for this.

yagiztw avatar Nov 06 '23 10:11 yagiztw

In general, the way to enable explicit self is --self insert, but I would not be surprised if it doesn't currently handle this case.

nicklockwood avatar Nov 10 '23 06:11 nicklockwood