Swift – Update Element of a Tuple at Specific Index
To update element of a Tuple at specific index in Swift, access the element using dot operator and index of the required element, and assign the new value to this element.
The code to update element at index=2 of a tuple
x.2 = new_value
In the following program, we take a Tuple
x, and update the element at index=2.
var x = (true, 35, "apple") x.2 = "banana" print(x)
(true, 35, "banana") Program ended with exit code: 0
In this Swift Tutorial, we have learned how to update the element of a Tuple at specific index, in Swift programming.