Redundant Nil Coalescing

nil coalescing operator is only evaluated if the lhs is nil, coalescing operator with nil as rhs is redundant

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

Non Triggering Examples

var myVar: Int?; myVar ?? 0

Triggering Examples

var myVar: Int? = nil; myVar ?? nil