Skip to content

Files

Latest commit

 

History

History
42 lines (21 loc) · 714 Bytes

empty_count.md

File metadata and controls

42 lines (21 loc) · 714 Bytes

Pattern: Missing use of isEmpty

Issue: -

Description

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

Further Reading