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

# Collection Implementations

## Topics

### Structures

[`struct Index`](/documentation/Swift/EnumeratedSequence/Index)

A type that represents a position in the collection.

### Instance Properties

[`var count: Int`](/documentation/Swift/EnumeratedSequence/count)

The number of elements in the collection.

[`var count: Int`](/documentation/Swift/EnumeratedSequence/count-3o2fx)

The number of elements in the collection.

[`var endIndex: EnumeratedSequence<Base>.Index`](/documentation/Swift/EnumeratedSequence/endIndex)

The collection’s “past the end” position—that is, the position one
greater than the last valid subscript argument.

[`var indices: DefaultIndices<Self>`](/documentation/Swift/EnumeratedSequence/indices-swift.property)

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

[`var isEmpty: Bool`](/documentation/Swift/EnumeratedSequence/isEmpty)

A Boolean value indicating whether the collection is empty.

[`var isEmpty: Bool`](/documentation/Swift/EnumeratedSequence/isEmpty-1yllc)

A Boolean value indicating whether the collection is empty.

[`var startIndex: EnumeratedSequence<Base>.Index`](/documentation/Swift/EnumeratedSequence/startIndex)

The position of the first element in a nonempty collection.

### Instance Methods

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

Returns the distance between two indices.

[`func distance(from: Self.Index, to: Self.Index) -> Int`](/documentation/Swift/EnumeratedSequence/distance(from:to:)-6kmqj)

Returns the distance between two indices.

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

Returns the first index in which an element of the collection satisfies
the given predicate.

[`func formIndex(inout Self.Index, offsetBy: Int)`](/documentation/Swift/EnumeratedSequence/formIndex(_:offsetBy:))

Offsets the given index by the specified distance.

[`func formIndex(inout Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Bool`](/documentation/Swift/EnumeratedSequence/formIndex(_:offsetBy:limitedBy:))

Offsets the given index by the specified distance, or so that it equals
the given limiting index.

[`func formIndex(after: inout Self.Index)`](/documentation/Swift/EnumeratedSequence/formIndex(after:))

Replaces the given index with its successor.

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

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

[`func index(Self.Index, offsetBy: Int) -> Self.Index`](/documentation/Swift/EnumeratedSequence/index(_:offsetBy:)-4bcg9)

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

[`func index(EnumeratedSequence<Base>.Index, offsetBy: Int, limitedBy: EnumeratedSequence<Base>.Index) -> EnumeratedSequence<Base>.Index?`](/documentation/Swift/EnumeratedSequence/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(Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Self.Index?`](/documentation/Swift/EnumeratedSequence/index(_:offsetBy:limitedBy:)-4rme3)

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

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

Returns the position immediately after the given index.

[`func indices(where: (Self.Element) throws -> Bool) rethrows -> RangeSet<Self.Index>`](/documentation/Swift/EnumeratedSequence/indices(where:))

Returns the indices of all the elements that match the given predicate.

[`func map<T, E>((Self.Element) throws(E) -> T) throws(E) -> [T]`](/documentation/Swift/EnumeratedSequence/map(_:)-9le0)

Returns an array containing the results of mapping the given closure
over the sequence’s elements.

[`func prefix(through: Self.Index) -> Self.SubSequence`](/documentation/Swift/EnumeratedSequence/prefix(through:))

Returns a subsequence from the start of the collection through the
specified position.

[`func prefix(upTo: Self.Index) -> Self.SubSequence`](/documentation/Swift/EnumeratedSequence/prefix(upTo:))

Returns a subsequence from the start of the collection up to, but not
including, the specified position.

[`func randomElement() -> Self.Element?`](/documentation/Swift/EnumeratedSequence/randomElement())

Returns a random element of the collection.

[`func randomElement<T>(using: inout T) -> Self.Element?`](/documentation/Swift/EnumeratedSequence/randomElement(using:))

Returns a random element of the collection, using the given generator as
a source for randomness.

[`func removingSubranges(RangeSet<Self.Index>) -> DiscontiguousSlice<Self>`](/documentation/Swift/EnumeratedSequence/removingSubranges(_:))

Returns a collection of the elements in this collection that are not
represented by the given range set.

[`func suffix(from: Self.Index) -> Self.SubSequence`](/documentation/Swift/EnumeratedSequence/suffix(from:))

Returns a subsequence from the specified position to the end of the
collection.

### Subscripts

[`subscript(EnumeratedSequence<Base>.Index) -> EnumeratedSequence<Base>.Element`](/documentation/Swift/EnumeratedSequence/subscript(_:))

Accesses the element at the specified position.

[`subscript(Range<Self.Index>) -> Slice<Self>`](/documentation/Swift/EnumeratedSequence/subscript(_:)-5gng6)

Accesses a contiguous subrange of the collection’s elements.

[`subscript(UnboundedRange) -> Self.SubSequence`](/documentation/Swift/EnumeratedSequence/subscript(_:)-7y5my)

[`subscript<R>(R) -> Self.SubSequence`](/documentation/Swift/EnumeratedSequence/subscript(_:)-8ubal)

Accesses the contiguous subrange of the collection’s elements specified
by a range expression.

[`subscript(RangeSet<Self.Index>) -> DiscontiguousSlice<Self>`](/documentation/Swift/EnumeratedSequence/subscript(_:)-91gqg)

Accesses a view of this collection with the elements at the given
indices.

### Type Aliases

[`typealias Indices`](/documentation/Swift/EnumeratedSequence/Indices)

A type that represents the indices that are valid for subscripting the
collection, in ascending order.

[`typealias SubSequence`](/documentation/Swift/EnumeratedSequence/SubSequence)

A collection representing a contiguous subrange of this collection’s
elements. The subsequence shares indices with the original collection.

---

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)