Empty Collection Literal

Prefer checking isEmpty over comparing collection to an empty array or dictionary literal

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

Non Triggering Examples

myArray = []
myArray.isEmpty
!myArray.isEmpty
myDict = [:]

Triggering Examples

myArray↓ == []
myArray↓ != []
myArray↓ == [ ]
myDict↓ == [:]
myDict↓ != [:]
myDict↓ == [: ]
myDict↓ == [ :]
myDict↓ == [ : ]