indexed

Returns a collection of pairs (i, x), where i represents an index of the collection, and x represents an element.

Indexed.swift:114
func indexed() -> IndexedCollection<Self>

Returns

A collection of paired indices and elements of this collection.

The indexed() method is similar to the standard library’s enumerated() method, but provides the index with each element instead of a zero-based counter.

This example iterates over the indices and elements of a set, building an array consisting of indices of names with five or fewer letters.

let names: Set = ["Sofia", "Camilla", "Martina", "Mateo", "Nicolás"]
var shorterIndices: [Set<String>.Index] = []
for (i, name) in names.indexed() {
    if name.count <= 5 {
        shorterIndices.append(i)
    }
}