Contains over Range Comparison to Nil

Prefer contains over range(of:) != nil and range(of:) == nil

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

Non Triggering Examples

let range = myString.range(of: "Test")
resourceString.range(of: rule.regex, options: .regularExpression) != nil

Triggering Examples

myString.range(of: "Test") != nil
myString.range(of: "Test") == nil