We can use the subscript syntax with a range operator to change the values of multiple elements. The following example shows how to do this:
var arrayOne = [1,2,3,4,5] arrayOne[1...2] = [12,13]//arrayOne contains 1,12,13,4 and 5
In the preceding code, the elements at indices 1 and 2 will be changed to numbers 12 and 13; therefore, arrayOne will contain 1, 12, 13, 4, and 5.
The number of elements that you are changing in the range operator does not need to match the number of values that you are passing in. Swift makes bulk changes by first removing the elements defined by the range operator and then inserting the new values. The following example demonstrates this concept:
var arrayOne = [1,2,3,4,5] arrayOne[1...3] ...