I probably missed an important information about swift. I have a map contains a key / swift array pair. I changed the array and the array inside the map was not changed. Cou
Array in Swift is defined as a struct, i.e. a value type. When you assign another variable to another variable of value type, it creates a copy of that second variable:
map["list"] = list // store a **copy** of list into map
To see the difference between value and reference type, change your array to its ObjectiveC cousin, NSMutableArray
, which is of reference type:
var map = [String: NSMutableArray]()
var list = NSMutableArray()
map["list"] = list
list.addObject("test")
print(map) // ["list": (test)]