Pattern: Missing use of isEmpty
Issue: -
Prefer checking isEmpty
over comparing count
to zero. For collections that don’t conform to RandomAccessCollection
, accessing the count property iterates through the elements of the collection.
Examples of correct code:
var count = 0
[Int]().isEmpty
[Int]().count > 1
[Int]().count == 1
Examples of incorrect code:
[Int]().↓count == 0
[Int]().↓count > 0
[Int]().↓count != 0
↓count == 0