The Set.enumerated() function in Swift returns a sequence of (index, value) pairs of a set. The index represents an element from a series of consecutive integers starting at zero. The value represents an element in the set.
set.enumerated()
This function takes no parameters.
The value returned is an enumerated sequence containing pairs of index and elements of a set. The first value of the pair represents the element's index. Its second value represents the element itself.
// create a setlet evenNumbers : Set = [10, 2, 6, 8, 4]// get the sequencelet sequence = evenNumbers.enumerated()for (x, y) in sequence{print(x, y)}
evenNumbers set and initialize it with some values.enumerated() function to get an enumerated sequence of pairs. We store the result inside the sequence variable.for-in loop or the for loop, we are able to print each pair of the sequence to the console.