Swift – Get Element of a Tuple at Specific Index
To get element of a Tuple at specific index in Swift, use dot operator and specify the index of the required value.
The code to get element at index=2 of a tuple
The above expression returns the value/element.
In the following program, we initialize a Tuple
x with values, and get the element at index=2.
var x = (true, 35, "apple") var e = x.2 print("Element : \(e)")
Element : apple Program ended with exit code: 0
In this Swift Tutorial, we have learned how to get the element of a Tuple at specific index, in Swift programming.