<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Substring/BidirectionalCollection-Implementations",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "BidirectionalCollection Implementations"
}
-->

# BidirectionalCollection Implementations

## Topics

### Instance Properties

[`var last: Self.Element?`](/documentation/Swift/Substring/last)

The last element of the collection.

### Instance Methods

[`func difference<C>(from: C) -> CollectionDifference<Self.Element>`](/documentation/Swift/Substring/difference(from:))

Returns the difference needed to produce this collection’s ordered
elements from the given collection.

[`func difference<C>(from: C, by: (C.Element, Self.Element) -> Bool) -> CollectionDifference<Self.Element>`](/documentation/Swift/Substring/difference(from:by:))

Returns the difference needed to produce this collection’s ordered
elements from the given collection, using the given predicate as an
equivalence test.

[`func distance(from: Substring.Index, to: Substring.Index) -> Int`](/documentation/Swift/Substring/distance(from:to:))

Returns the distance between two indices.

[`func dropLast(Int) -> Self.SubSequence`](/documentation/Swift/Substring/dropLast(_:))

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

[`func formIndex(before: inout Self.Index)`](/documentation/Swift/Substring/formIndex(before:))

Replaces the given index with its predecessor.

[`func index(Substring.Index, offsetBy: Int) -> Substring.Index`](/documentation/Swift/Substring/index(_:offsetBy:))

Returns an index that is the specified distance from the given index.

[`func index(Substring.Index, offsetBy: Int, limitedBy: Substring.Index) -> Substring.Index?`](/documentation/Swift/Substring/index(_:offsetBy:limitedBy:))

Returns an index that is the specified distance from the given index,
unless that distance is beyond a given limiting index.

[`func index(after: Substring.Index) -> Substring.Index`](/documentation/Swift/Substring/index(after:))

Returns the position immediately after the given index.

[`func index(before: Substring.Index) -> Substring.Index`](/documentation/Swift/Substring/index(before:))

Returns the position immediately before the given index.

[`func last(where: (Self.Element) throws -> Bool) rethrows -> Self.Element?`](/documentation/Swift/Substring/last(where:))

Returns the last element of the sequence that satisfies the given
predicate.

[`func lastIndex(of: Self.Element) -> Self.Index?`](/documentation/Swift/Substring/lastIndex(of:))

Returns the last index where the specified value appears in the
collection.

[`func lastIndex(where: (Self.Element) throws -> Bool) rethrows -> Self.Index?`](/documentation/Swift/Substring/lastIndex(where:))

Returns the index of the last element in the collection that matches the
given predicate.

[`func popLast() -> Self.Element?`](/documentation/Swift/Substring/popLast()-7k3s0)

Removes and returns the last element of the collection.

[`func removeLast() -> Self.Element`](/documentation/Swift/Substring/removeLast()-2gcne)

Removes and returns the last element of the collection.

[`func removeLast(Int)`](/documentation/Swift/Substring/removeLast(_:)-8r1d9)

Removes the given number of elements from the end of the collection.

[`func reversed() -> ReversedCollection<Self>`](/documentation/Swift/Substring/reversed())

Returns a view presenting the elements of the collection in reverse
order.

[`func suffix(Int) -> Self.SubSequence`](/documentation/Swift/Substring/suffix(_:))

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

### Subscripts

[`subscript(Range<Substring.Index>) -> Substring`](/documentation/Swift/Substring/subscript(_:)-6e3qj)

Accesses a contiguous subrange of the collection’s elements.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)