Static Over Final Class

Prefer static over class when the declaration is not allowed to be overridden in child classes due to its context being final. Likewise, the compiler complains about open being used in final classes.

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

Non Triggering Examples

class C {
    static func f() {}
}
class C {
    static var i: Int { 0 }
}
class C {
    static subscript(_: Int) -> Int { 0 }
}
class C {
    class func f() {}
}
final class C {}
final class C {
    class D {
      class func f() {}
    }
}

Triggering Examples

class C {
    final class func f() {}
}
class C {
    final class var i: Int { 0 }
}
class C {
    final class subscript(_: Int) -> Int { 0 }
}
final class C {
    class func f() {}
}
class C {
    final class D {
        class func f() {}
    }
}