Structure

IndexPath

A list of indexes that together represent the path to a specific location in a tree of nested arrays.

Overview

Each index in an index path represents the index into an array of children from one node in the tree to another, deeper, node.

Topics

Creating Index Paths

init()

Creates an empty index path.

init(index: IndexPath.Element)

Creates an index path with a single element.

init(arrayLiteral: IndexPath.Element...)

Creates an index path from an array literal.

init(indexes: Array<IndexPath.Element>)

Creates an index path from an array of elements.

init<ElementSequence>(indexes: ElementSequence)

Creates an index path from a sequence of integers.

typealias IndexPath.Element

A type that represents one node of an index path.

Working with Special Node Names

UIKit and AppKit supply specialized names for the first two index path nodes for use when working with table views and collection views.

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 indices: DefaultRandomAccessIndices<IndexPath>

The indices that are valid for subscripting the collection, in ascending order.

var isEmpty: Bool

A Boolean value that is true when the index path contains no nodes.

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: LazyCollection<IndexPath>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

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 lazy: LazyBidirectionalCollection<IndexPath>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

var lazy: LazyRandomAccessCollection<IndexPath>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

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.

Counting Nodes

var isEmpty: Bool

A Boolean value that is true when the index path contains no nodes.

Accessing Nodes

Adding Nodes

static func +(IndexPath, IndexPath)

Combines the elements of two index paths into a single index path.

static func +=(inout IndexPath, IndexPath)

Appends the elements of another index path to this index path.

static func <(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is less than the second when comparing elements in depth-first traversal order.

static func <=(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is less than or equal to the second when comparing elements in depth-first traversal order.

static func ==(IndexPath, IndexPath)

Returns a Boolean that is true if all nodes of the first index path are equal to those of the second in order.

static func >(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is greater than the second when comparing elements in depth-first traversal order.

static func >=(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is greater than or equal to the second when comparing elements in depth-first traversal order.

Removing Nodes

func removeFirst()

Removes and returns the first node of the index path.

func removeFirst(Int)

Removes the specified number of nodes from the beginning of the index path.

func removeLast()

Removes and returns the last node of the index path.

func removeLast(Int)

Removes the given number of nodes from the end of the index path.

func popFirst()

Removes and returns the first node of the index path.

func popLast()

Removes and returns the last node of the index path.

Finding Nodes

func max()

Returns the maximum element in the sequence.

func min()

Returns the minimum element in the sequence.

Selecting Nodes

func append(IndexPath)

Appends the nodes of another index path to this one.

func append(Array<IndexPath.Element>)

Appends an array of elements to this index path as additional nodes.

func append(IndexPath.Element)

Appends a single element to this index path as a new node.

func appending(IndexPath.Element)

Returns a new index path containing the elements of this one plus the given element.

func appending(IndexPath)

Returns a new index path containing the elements of this one plus those of another index path.

func appending(Array<IndexPath.Element>)

Returns a new index path containing the elements of this one plus an array of additional elements.

func compare(IndexPath)

Compares this index path to another in depth-first traversal order.

func dropFirst()

Returns a subsequence containing all but the first node of the index path.

func dropFirst(Int)

Returns a subsequence containing all but the given number of initial elements.

func dropLast()

Return a new index path containing all but the last element.

func dropLast(Int)

Returns a subsequence containing all but the specified number of final nodes.

func elementsEqual<OtherSequence>(OtherSequence)

Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.

func enumerated()

Returns a sequence of pairs (n, x), where n represents a consecutive integer starting at zero, and x represents an element of the sequence.

func index(after: IndexPath.Index)

Returns the index that follows the given index.

func index(before: IndexPath.Index)

Returns the index that precedes the given index.

func lexicographicallyPrecedes<OtherSequence>(OtherSequence)

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<) to compare elements.

func makeIterator()

Returns an iterator over the nodes of the index path.

func max()

Returns the maximum element in the sequence.

func min()

Returns the minimum element in the sequence.

func popFirst()

Removes and returns the first node of the index path.

func popLast()

Removes and returns the last node of the index path.

func prefix(Int)

Returns a subsequence, up to the specified maximum length, containing the initial nodes of the index path.

func prefix(through: Array.Index)

Returns a subsequence from the start of the index path through the specified node.

func prefix(upTo: Array.Index)

Returns a subsequence from the start of the index path up to, but not including, the specified node.

func removeFirst()

Removes and returns the first node of the index path.

func removeFirst(Int)

Removes the specified number of nodes from the beginning of the index path.

func removeLast()

Removes and returns the last node of the index path.

func removeLast(Int)

Removes the given number of nodes from the end of the index path.

func reversed()

Returns a view presenting the nodes of the index path in reverse order.

func sorted()

Returns the nodes of the index path sorted in ascending order according to each node's value.

func starts<PossiblePrefix>(with: PossiblePrefix)

Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.

func suffix(Int)

Returns a subsequence, up to the given maximum length, containing the final elements of the index path.

func suffix(from: Array.Index)

Returns a subsequence from the specified position to the end of the index path.

Excluding Nodes

func dropFirst()

Returns a subsequence containing all but the first node of the index path.

func dropFirst(Int)

Returns a subsequence containing all but the given number of initial elements.

func dropLast()

Return a new index path containing all but the last element.

func dropLast(Int)

Returns a subsequence containing all but the specified number of final nodes.

Transforming Index Paths

var lazy: LazyCollection<IndexPath>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

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 lazy: LazyBidirectionalCollection<IndexPath>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

var lazy: LazyRandomAccessCollection<IndexPath>

A view onto this collection that provides lazy implementations of normally eager operations, such as map and filter.

Iterating over Nodes

func enumerated()

Returns a sequence of pairs (n, x), where n represents a consecutive integer starting at zero, and x represents an element of the sequence.

func makeIterator()

Returns an iterator over the nodes of the index path.

Sorting Nodes

func sorted()

Returns the nodes of the index path sorted in ascending order according to each node's value.

func reversed()

Returns a view presenting the nodes of the index path in reverse order.

Comparing Index Paths

func compare(IndexPath)

Compares this index path to another in depth-first traversal order.

func lexicographicallyPrecedes<OtherSequence>(OtherSequence)

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<) to compare elements.

static func <(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is less than the second when comparing elements in depth-first traversal order.

static func <=(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is less than or equal to the second when comparing elements in depth-first traversal order.

static func ==(IndexPath, IndexPath)

Returns a Boolean that is true if all nodes of the first index path are equal to those of the second in order.

static func >(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is greater than the second when comparing elements in depth-first traversal order.

static func >=(IndexPath, IndexPath)

Returns a Boolean that is true if the first index path is greater than or equal to the second when comparing elements in depth-first traversal order.

func starts<PossiblePrefix>(with: PossiblePrefix)

Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.

func elementsEqual<OtherSequence>(OtherSequence)

Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.

Manipulating Indexes

typealias IndexPath.Index

A type that points to a particular node in an index path, similar to an array index.

var startIndex: IndexPath.Index

The index of the first node in the index path.

var endIndex: IndexPath.Index

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

func index(after: IndexPath.Index)

Returns the index that follows the given index.

func index(before: IndexPath.Index)

Returns the index that precedes the given index.

typealias IndexPath.Indices

A type that represents a group of nodes in an index path.

var indices: DefaultRandomAccessIndices<IndexPath>

The indices that are valid for subscripting the collection, in ascending order.

Describing an Index Path

var description: String

A textual description of the index path.

var debugDescription: String

A textual description of the index path suitable for debugging.

var customMirror: Mirror

A mirror that reflects the index path.

var hashValue: Int

The computed hash value for the index path.

Using Reference Types

class NSIndexPath

An object containing a list of indexes that bridges to IndexPath; use NSIndexPath when you need reference semantics or other Foundation-specific behavior.

typealias IndexPath.ReferenceType

An alias for this value type's equivalent reference type.

Initializers

init(item: Int, section: Int)

Creates an index path that references an item in a particular section.

init(item: Int, section: Int)

Creates an index path that references an item in a particular section.

init(row: Int, section: Int)

Creates an index path that references a row in a particular section.

See Also

Indexes

struct IndexSet

A collection of unique integer values that represent the indexes of elements in another collection.