Adding and removing of dictionaries elements in Swift
Forums:
var dic = [Int : String]()
dic[1] = "one"
dic[2] = "two"
dic[3] = "tree"
//dic is [1: one, 2: two, 3: tree]
dic[3] = "three"
//dic is [1: one, 2: two, 3: three]
dic[3] = nil
//dic is [1: one, 2: two]
dic.removeValueForKey(2)
//dic is [1: one]
dic.removeAll()
//dic is empty
- Log in to post comments