Swift Language Value Semantics

Download Swift Language for free

Example

Copying an array will copy all of the items inside the original array.

Changing the new array will not change the original array.

var originalArray = ["Swift", "is", "great!"]
var newArray = originalArray
newArray[2] = "awesome!"
//originalArray = ["Swift", "is", "great!"]
//newArray = ["Swift", "is", "awesome!"]

Copied arrays will share the same space in memory as the original until they are changed. As a result of this there is a performance hit when the copied array is given its own space in memory as it is changed for the first time.

Associated Objects