Initializerswift 6.1.2Swift

init(_:)

Creates a new index into a reversed collection for the position before the specified index.

init(_ base: Base.Index)

Parameters

base

The position after the element to create an index for.

When you create an index into a reversed collection using base, an index from the underlying collection, the resulting index is the position of the element before the element referenced by base. The following example creates a new ReversedIndex from the index of the "a" character in a string’s character view.

let name = "Horatio"
let aIndex = name.firstIndex(of: "a")!
// name[aIndex] == "a"

let reversedName = name.reversed()
let i = ReversedCollection<String>.Index(aIndex)
// reversedName[i] == "r"

The element at the position created using ReversedIndex<...>(aIndex) is "r", the character before "a" in the name string.