Override in Extension

Extensions shouldn’t override declarations

  • Identifier: override_in_extension
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

extension Person {
  var age: Int { return 42 }
}
extension Person {
  func celebrateBirthday() {}
}
class Employee: Person {
  override func celebrateBirthday() {}
}
class Foo: NSObject {}
extension Foo {
    override var description: String { return "" }
}
struct Foo {
    class Bar: NSObject {}
}
extension Foo.Bar {
    override var description: String { return "" }
}

Triggering Examples

extension Person {
  override var age: Int { return 42 }
}
extension Person {
  override func celebrateBirthday() {}
}