---
title: "index(_:offsetBy:)"
framework: Swift
role: symbol
role_heading: Instance Method
platforms: [iOS 27.0+, iPadOS 27.0+, Mac Catalyst 27.0+, macOS 27.0+, tvOS 27.0+, visionOS 27.0+, watchOS 27.0+]
path: "swift/uniquearray/index(_:offsetby:)"
---

# index(_:offsetBy:)

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

## Declaration

```swift
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

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

Discussion The value passed as n must not offset index beyond the bounds of the array. note: To improve performance, this method does not validate that the given index is valid before offseting it. Index validation is deferred until the resulting index is used to access an element. This optimization may be removed in future versions; do not rely on it. note: O(1)
