Instance Property

isEmpty

A Boolean value indicating whether the collection is empty.

Declaration

var isEmpty: Bool { get }

Discussion

When you need to check whether your collection is empty, use the isEmpty property instead of checking that the count property is equal to zero. For collections that don’t conform to RandomAccessCollection, accessing the count property iterates through the elements of the collection.

let horseName = "Silver"
if horseName.isEmpty {
    print("I've been through the desert on a horse with no name.")
} else {
    print("Hi ho, \(horseName)!")
}
// Prints "Hi ho, Silver!")

Complexity: O(1)

See Also

Working with Special Node Names

var customMirror: Mirror

A mirror that reflects the index path.

var debugDescription: String

A textual description of the index path suitable for debugging.

var description: String

A textual description of the index path.

var endIndex: IndexPath.Index

One past the index of the last node in the index path.

var hashValue: Int

The computed hash value for the index path.

var item: Int

The value of the item element of the index path.

var item: Int

The value of the item element of the index path.

var lazy: LazySequence<IndexPath>

A sequence containing the same elements as this sequence, but on which some operations, such as map and filter, are implemented lazily.

var row: Int

The value of the row element of the index path.

var section: Int

The value of the section element of the index path.

var section: Int

The value of the section element of the index path.

var startIndex: IndexPath.Index

The index of the first node in the index path.