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

# Collection Implementations

## Topics

### Instance Properties

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

The number of elements in the collection.

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

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

[`var first: Self.Element?`](/documentation/Swift/Slice/first)

The first element of the collection.

[`var indices: Slice<Base>.Indices`](/documentation/Swift/Slice/indices-swift.property)

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

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

A Boolean value indicating whether the collection is empty.

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

The position of the first element in a nonempty collection.

[`var underestimatedCount: Int`](/documentation/Swift/Slice/underestimatedCount)

A value less than or equal to the number of elements in the collection.

### Instance Methods

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

Returns the distance between two indices.

[`func drop(while: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence`](/documentation/Swift/Slice/drop(while:))

Returns a subsequence by skipping elements while `predicate` returns
`true` and returning the remaining elements.

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

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

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

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

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

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

[`func firstIndex(where: (Self.Element) throws -> Bool) rethrows -> Self.Index?`](/documentation/Swift/Slice/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/Slice/formIndex(_:offsetBy:))

Offsets the given index by the specified distance.

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

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

[`func formIndex(after: inout Slice<Base>.Index)`](/documentation/Swift/Slice/formIndex(after:))

Replaces the given index with its successor.

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

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

[`func index(Slice<Base>.Index, offsetBy: Int, limitedBy: Slice<Base>.Index) -> Slice<Base>.Index?`](/documentation/Swift/Slice/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: Slice<Base>.Index) -> Slice<Base>.Index`](/documentation/Swift/Slice/index(after:))

Returns the position immediately after the given index.

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

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

[`func indices(of: Self.Element) -> RangeSet<Self.Index>`](/documentation/Swift/Slice/indices(of:))

Returns the indices of all the elements that are equal to the given
element.

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

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

[`func makeIterator() -> IndexingIterator<Self>`](/documentation/Swift/Slice/makeIterator())

Returns an iterator over the elements of the collection.

[`func map<T, E>((Self.Element) throws(E) -> T) throws(E) -> [T]`](/documentation/Swift/Slice/map(_:)-3jfli)

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

[`func popFirst() -> Self.Element?`](/documentation/Swift/Slice/popFirst())

Removes and returns the first element of the collection.

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

Returns a subsequence, up to the specified maximum length, containing
the initial elements of the collection.

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

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

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

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

[`func prefix(while: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence`](/documentation/Swift/Slice/prefix(while:))

Returns a subsequence containing the initial elements until `predicate`
returns `false` and skipping the remaining elements.

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

Returns a random element of the collection.

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

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

[`func removeFirst() -> Self.Element`](/documentation/Swift/Slice/removeFirst()-2564w)

Removes and returns the first element of the collection.

[`func removeFirst(Int)`](/documentation/Swift/Slice/removeFirst(_:)-3pkd7)

Removes the specified number of elements from the beginning of the
collection.

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

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

[`func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Self.Element) throws -> Bool) rethrows -> [Self.SubSequence]`](/documentation/Swift/Slice/split(maxSplits:omittingEmptySubsequences:whereSeparator:))

Returns the longest possible subsequences of the collection, in order,
that don’t contain elements satisfying the given predicate.

[`func split(separator: Self.Element, maxSplits: Int, omittingEmptySubsequences: Bool) -> [Self.SubSequence]`](/documentation/Swift/Slice/split(separator:maxSplits:omittingEmptySubsequences:)-5z4op)

Returns the longest possible subsequences of the collection, in order,
around elements equal to the given element.

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

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

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

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

### Subscripts

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

Accesses the element at the specified position.

[`subscript(RangeSet<Self.Index>) -> DiscontiguousSlice<Self>`](/documentation/Swift/Slice/subscript(_:)-3p40a)

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

[`subscript(UnboundedRange) -> Self.SubSequence`](/documentation/Swift/Slice/subscript(_:)-520wp)

[`subscript(Range<Slice<Base>.Index>) -> Slice<Base>`](/documentation/Swift/Slice/subscript(_:)-5pgrv)

Accesses a contiguous subrange of the collection’s elements.

[`subscript<R>(R) -> Self.SubSequence`](/documentation/Swift/Slice/subscript(_:)-5rdkr)

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

[`subscript(Range<Self.Index>) -> Slice<Self>`](/documentation/Swift/Slice/subscript(_:)-7bg96)

Accesses a contiguous subrange of the collection’s elements.

### Type Aliases

[`typealias Index`](/documentation/Swift/Slice/Index)

A type that represents a position in the collection.

[`typealias Indices`](/documentation/Swift/Slice/Indices-swift.typealias)

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

[`typealias Iterator`](/documentation/Swift/Slice/Iterator)

A type that provides the collection’s iteration interface and
encapsulates its iteration state.

[`typealias SubSequence`](/documentation/Swift/Slice/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)