: Playground-noun:a place where people can play
Import UIKit
/*:
Dictionary
* and OC difference
* 1. {} replaced by []
* 2. Remove All @
* variable dictionary var
* immutable dictionary let
*/
var dict = ["name": "Lnj", "Age":
Let dict2: [String : nsobject] = ["name": "Lnj", "Age": 30< c28>]
Anyobject = = NSObject
Let dict3: Dictionary<String, anyobject> = ["name": "Lnj", "Age":
Note : in Enterprise Development , the most frequently used dictionary type is [String:anyobject]
Let dict4 = [String: anyobject] ()
Take value
Dict["name"]
Update
If you assign a value to an existing key , It is the update
Dict["name"] = "Zs"
Dict
Increase
If you assign a value to a nonexistent key , It is added
Dict["score"] = 99.9
Dict
Delete
Dict. Removevalueforkey("name")
Dict
Traverse
For key in dict. Keys
{
Print(dict[key])
}
The key in the dictionary is assigned to K, and the value in the dictionary is assigned to v
Note : K and v write casually , but note that key must be assigned to the previous traversal , value must be assigned to the back of a traversal
for (key, value) in dict
{
print(key)
print(value)
}
Swift 2.0 Syntax Dictionary