Empty Count

Prefer checking isEmpty over comparing count to zero.

  • Identifier: empty_count
  • Enabled by default: Disabled
  • Supports autocorrection: No
  • Kind: performance
  • Analyzer rule: No
  • Minimum Swift compiler version: 3.0.0
  • Default configuration: error, only_after_dot: false

Non Triggering Examples

var count = 0

[Int]().isEmpty

[Int]().count > 1

[Int]().count == 1

[Int]().count == 0xff

[Int]().count == 0b01

[Int]().count == 0o07

discount == 0

order.discount == 0

Triggering Examples

[Int]().count == 0

[Int]().count > 0

[Int]().count != 0

[Int]().count == 0x0

[Int]().count == 0x00_00

[Int]().count == 0b00

[Int]().count == 0o00

count == 0