---
title: "index(before:)"
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(before:)"
---

# index(before:)

Returns the position immediately before the given index.

## Declaration

```swift
func index(before index: Int) -> Int
```

## Parameters

- `index`: A valid index of the array. i must be greater than startIndex.

## Return Value

Return Value The index immediately preceding i.

## Discussion

Discussion note: To improve performance, this method does not validate that the index is valid before decrementing 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)
