Reputation: 17080
I have a dictionary which contains another dictionary:
var channelDict = Dictionary<String, AnyObject>()
channelDict["image"] = Dictionary<String, AnyObject>()
Now I want to add value to the child dictionary, I tried the following but nothing worked:
channelDict["image"]["key"] = "value"
var:Dictionary<String, AnyObject> dict = channelDict["image"]
dict["key"] = "value"
if var dict = channelDict["image"] {
dict["Key"] = "value"
}
Upvotes: 2
Views: 421
Reputation: 12015
This way you can add a dictionary to the "image"
key:
channelDict["image"] = ["key": "value"]
UPDATED
And if you want to add values to the inner dict and keep the existing values, you should create a temporary variable like this:
var innerDict = channelDict["image"] as [String: AnyObject]
innerDict["dsa"] = "dsa"
channelDict["image"] = innerDict
Upvotes: 2