我知道Swift中的struct,array,dictionary ...是通过值传递的,而类是通过引用传递的。但是在下面的代码中,是否仍然为常量数组引用?
let arr1 = [1,2,3]
let arr2 = arr1
另一个问题,Swift只会在你修改它时复制一个数组吗?
var anotherArray1 = [1,2,3]
var anotherArray2 = anotherArray1 // anotherArray1 and anotherArray2 reference the the same array
anotherArray2[0] = 10 //Swift will copy values in anotherArray1 into anotherArray2 then changing value at 0 index to 10