Explicit Enum Raw Value

Enums should be explicitly assigned their raw values

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

Non Triggering Examples

enum Numbers {
  case int(Int)
  case short(Int16)
}
enum Numbers: Int {
  case one = 1
  case two = 2
}
enum Numbers: Double {
  case one = 1.1
  case two = 2.2
}
enum Numbers: String {
  case one = "one"
  case two = "two"
}
protocol Algebra {}
enum Numbers: Algebra {
  case one
}

Triggering Examples

enum Numbers: Int {
  case one = 10, two, three = 30
}
enum Numbers: NSInteger {
  case one
}
enum Numbers: String {
  case one
  case two
}
enum Numbers: String {
   case one, two = "two"
}
enum Numbers: Decimal {
  case one, two
}
enum Outer {
    enum Numbers: Decimal {
      case one, two
    }
}