Instance Property

count

The number of elements in the collection.

Declaration

var count: Int { get }
Available when Base conforms to Collection.

Discussion

To check whether the collection is empty, use its isEmpty property instead of comparing count to zero. Unless the collection guarantees random-access performance, calculating count can be an O(n) operation.

Complexity: O(1) if Index conforms to RandomAccessIndex; O(n) otherwise.

Relationships

From Protocol