BidirectionalCollection

    A collection that supports backward as well as forward traversal.

    protocol BidirectionalCollection<Element> : Collection where Self.Indices : BidirectionalCollection, Self.SubSequence : BidirectionalCollection
    Browse conforming types

    Bidirectional collections offer traversal backward from any valid index, not including a collection’s startIndex. Bidirectional collections can therefore offer additional operations, such as a last property that provides efficient access to the last element and a reversed() method that presents the elements in reverse order. In addition, bidirectional collections have more efficient implementations of some sequence and collection methods, such as suffix(_:).

    Conforming to the BidirectionalCollection Protocol

    To add BidirectionalProtocol conformance to your custom types, implement the index(before:) method in addition to the requirements of the Collection protocol.

    Indices that are moved forward and backward in a bidirectional collection move by the same amount in each direction. That is, for any valid index i into a bidirectional collection c:

    • If i >= c.startIndex && i < c.endIndex, then c.index(before: c.index(after: i)) == i.

    • If i > c.startIndex && i <= c.endIndex, then c.index(after: c.index(before: i)) == i.

    Valid indices are exactly those indices that are reachable from the collection’s startIndex by repeated applications of index(after:), up to, and including, the endIndex.

    Supertypes

    Requirements

    Type members

    Instance members

    Citizens in Swift

    Instance members

    Subtypes

    Citizens in Swift

    where Self == Self.SubSequence

    Instance members

    Citizens in Swift

    where Self.Element:Equatable

    Instance members

    Citizens in Swift

    where Self.Element == String

    Instance members

    Available in _RegexParser

    Instance members

    Available in _StringProcessing

    where Self.Element:Comparable

    Instance members

    Available in _StringProcessing

    where Self.SubSequence == Substring

    Instance members

    Available in RegexBuilder

    where Self.SubSequence == Substring

    Instance members

    Available in Cxx

    Subtypes

    Available in FoundationEssentials

    Subtypes

    Extension in Algorithms

    Instance members

    Extension in Algorithms

    Instance members

    Extension in Algorithms

    where Self == Self.SubSequence

    Instance members