SwiftFormat
SwiftFormat copied to clipboard
Don't have implicit self for weak self captures, after self is unwrapped
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.
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.