Returns an index that is the specified distance from the given index.
- Xcode 10.0+
- Swift Standard Library
A valid index of the collection.
The distance to offset
nmust not be negative unless the collection conforms to the
An index offset by
n from the index
n is positive, this is the same value as the result of
n calls to
n is negative, this is the same value as the result of
-n calls to
The following example obtains an index advanced four positions from a string’s starting index and then prints the character at that position.
The value passed as
n must not offset
i beyond the bounds of the collection.
Complexity: O(1) if the collection conforms to
Random; otherwise, O(n), where n is the absolute value of