简体   繁体   中英

How to Append to complex dictionary types in swift 3

How to append some empty array values to the below dictionary.

var results:Dictionary<String, Array<Dictionary<String, Any>> = [:]

results["key"] = nil doesn't work for me.

I want to have a dictionary like

{
"key1" : [],
"key2" : [],
"key3" : []
}

And should be possible to add Dictionary<String, Any> later in the place of ()

First of all, your first line is illegal. It won't even compile. Please try always to show real code. So, your declaration might look like this:

var results : Dictionary<String, Array<Dictionary<String, Any>>> = [:]

Then to add an empty array to the dictionary, you would say:

results["key"] = []

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM