Unneeded Override

ID

swift.unneeded_override

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Swift

Tags

code-smell, dead-code

Description

Reports an override func whose body is a single call to super.<sameName>(…​) with the same argument count as the function’s parameters. The override adds no behaviour and just shadows the parent’s method.

override func viewDidLoad() {                      // FLAW
    super.viewDidLoad()
}

override func numberOfRows(_ section: Int) -> Int {  // FLAW
    return super.numberOfRows(section)
}

override func viewDidLoad() {                      // OK — adds work
    super.viewDidLoad()
    setupSubviews()
}

Rationale

A pass-through override locks subclassers into a no-op layer that their compiler cannot optimise away (the dispatch is dynamic) and that future readers must investigate to confirm it really is just a forward. If the only purpose was to add a doc comment, the doc belongs on the parent declaration.

Remediation

Delete the override. If the override was a placeholder for future work, leave a TODO on the parent or add // MARK: near the class declaration.