Value Semantics
suggest changeCopying an array copies its elements. For String values, changing the new array will not change the original array. If an element is a class instance, both arrays still refer to that same instance.
var originalArray = ["Swift", "is", "great!"]
var newArray = originalArray
newArray[2] = "awesome!"
//originalArray = ["Swift", "is", "great!"]
//newArray = ["Swift", "is", "awesome!"]
Copied arrays share storage with the original until one of them changes. The first change copies that storage, so it costs more than later changes to the same array.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents