aldirc aldirc - 1 year ago 102
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download