protocol IndexableBase

A type that provides subscript access to its elements, with forward index traversal.

In most cases, it's best to ignore this protocol and use the Collection protocol instead, because it has a more complete interface.

Deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead.

Inheritance View Protocol Hierarchy →
Associated Types
Index : Comparable

A type that represents a position in the collection.

Valid indices consist of the position of every element and a "past the end" position that's not valid for use as a subscript argument.

See Also: endIndex


A sequence that can represent a contiguous subrange of the collection's elements.

Import import Swift

Instance Variables

var endIndex: Self.Index Required

The collection's "past the end" position---that is, the position one greater than the last valid subscript argument.

When you need a range that includes the last element of a collection, use the half-open range operator (..<) with endIndex. The ..< operator creates a range that doesn't include the upper bound, so it's always safe to use with endIndex. For example:

let numbers = [10, 20, 30, 40, 50]
if let index = numbers.index(of: 30) {
    print(numbers[index ..< numbers.endIndex])
// Prints "[30, 40, 50]"

If the collection is empty, endIndex is equal to startIndex.


var endIndex: Self.Index { get }
var startIndex: Self.Index Required

The position of the first element in a nonempty collection.

If the collection is empty, startIndex is equal to endIndex.


var startIndex: Self.Index { get }


subscript(_: Self.Index) Required

Accesses the element at the specified position.

The following example accesses an element of an array through its subscript to print its value:

var streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
// Prints "Bryant"

You can subscript a collection with any valid index other than the collection's end index. The end index refers to the position one past the last element of a collection, so it doesn't correspond with an element.

position: The position of the element to access. position must be a valid index of the collection that is not equal to the endIndex property.


subscript(position: Self.Index) -> Self._Element { get }
subscript(_: Range<Self.Index>) Required

Accesses the subsequence bounded by the given range.

bounds: A range of the collection's indices. The upper and lower bounds of the bounds range must be valid indices of the collection.


subscript(bounds: Range<Self.Index>) -> Self.SubSequence { get }

Instance Methods

func formIndex(after:) Required

Replaces the given index with its successor.

i: A valid index of the collection. i must be less than endIndex.


func formIndex(after i: inout Self.Index)
func index(after:) Required

Returns the position immediately after the given index.

i: A valid index of the collection. i must be less than endIndex. Returns: The index value immediately after i.


func index(after i: Self.Index) -> Self.Index