aldirc aldirc - 5 months ago 53
Swift Question

Swift Array var issue

var dictionary = ["1": ["One","Two","Three"],
"2": ["A","B","C"]

var array = dictionary ["1"]

print("array Count: \(array!.count) array In DictionaryCount: \(dictionary ["1"]!.count)")
//array Count: 4 array In Dictionary Count: 3

var array has append "Four",but in dictionary it does't, how to append an element in dictionary?


Unlike Objective-C, collections in Swift are not reference types. It means that arrays, dictionaries, strings and almost everything behave like primitives in C/Objective-C (except objects, which are instances of classes, not structures or enums)

You can find more details in this official Apple page: Value and Reference Types