Skip to content

Files

Latest commit

 

History

History
56 lines (37 loc) · 823 Bytes

override_in_extension.md

File metadata and controls

56 lines (37 loc) · 823 Bytes

Pattern: Override in extension

Issue: -

Description

Extensions shouldn't override declarations.

Examples of correct code:

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 "" }
}

Examples of incorrect code:

extension Person {
  override var age: Int { return 42 }
}


extension Person {
  overridefunc celebrateBirthday() {}
}

Further Reading