According to Apple's Swift guide:
If you create an array, a set, or a dictionary, and assign it to a variable, the collection that is created will be mutable. This means that you can change (or mutate) the collection after it is created by adding, removing, or changing items in the collection. If you assign an array, a set, or a dictionary to a constant, that collection is immutable, and its size and contents cannot be changed.
But in Xcode 7.2.1, I get these results:
import Foundation //**Added per comments**
var data: [Int] = [10, 20]
print(unsafeAddressOf(data))
data.append(30)
print(data)
print(unsafeAddressOf(data))
--output:--
0x00007ff9a3e176a0
[10, 20, 30]
0x00007ff9a3e1d310
Because I assigned the array to a var, I expected to see the same address for data after appending a value to data.
Another example:
class Item {
}
var data: [Item] = [Item(), Item()]
print(unsafeAddressOf(data))
data.append(Item())
print(data)
print(unsafeAddressOf(data))
--output:--
0x00007f86a941b090
[Item, Item, Item]
0x00007f86a961f4c0
And another:
var data: [String] = ["a", "b"]
print(unsafeAddressOf(data))
data[0] = "A"
print(data)
print(unsafeAddressOf(data))
--output:--
0x00007faa6b624690
["A", "b"]
0x00007faa6b704840
[Int]does not confirm toAnyObject.