Contents

index(_:offsetBy:)

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

Declaration

func index(_ index: Int, offsetBy n: Int) -> Int

Parameters

  • index:

    A valid index of the array.

  • n:

    The distance by which to offset index.

Return Value

An index offset by distance from index. If n is positive, this is the same value as the result of n calls to index(after:). If n is negative, this is the same value as the result of abs(n) calls to index(before:).

Discussion

The value passed as n must not offset index beyond the bounds of the array.