Returns an index that is the specified distance from the given index.
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 9.3+
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