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

# RandomAccessCollection Implementations

## Topics

### Instance Properties

[`var endIndex: Int`](/documentation/Swift/ArraySlice/endIndex)

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

[`var indices: Range<Self.Index>`](/documentation/Swift/ArraySlice/indices-swift.property)

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

[`var startIndex: Int`](/documentation/Swift/ArraySlice/startIndex)

The position of the first element in a nonempty array.

### Instance Methods

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

Returns the distance between two indices.

[`func formIndex(after: inout Int)`](/documentation/Swift/ArraySlice/formIndex(after:))

Replaces the given index with its successor.

[`func formIndex(before: inout Int)`](/documentation/Swift/ArraySlice/formIndex(before:))

Replaces the given index with its predecessor.

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

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

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

Returns the position immediately after the given index.

[`func index(before: Int) -> Int`](/documentation/Swift/ArraySlice/index(before:))

Returns the position immediately before the given index.

### Subscripts

[`subscript(Int) -> Element`](/documentation/Swift/ArraySlice/subscript(_:)-4e8d9)

Accesses the element at the specified position.

[`subscript(Range<Int>) -> ArraySlice<Element>`](/documentation/Swift/ArraySlice/subscript(_:)-63qca)

Accesses a contiguous subrange of the array’s elements.

### Type Aliases

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

The index type for arrays, `Int`.

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

The type that represents the indices that are valid for subscripting an
array, in ascending order.

---

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)