Consider the code below:
let dict = [
"key1" : 1,
"key2" : 2,
"key3" : 3,
"key4" : 4,
"key5" : 5
]
let array = dict.map{$0}
for item in array {
print(item)
}
What you get from the print statements is:
("key2", 2)
("key3", 3)
("key4", 4)
("key5", 5)
("key1", 1)
The key/value pairs from the dictionary are converted to tuples. I would have expected to get back an array of single-value dictionaries.
Why does the map statement convert my items to tuples, and where is this behavior documented?
It's a simple matter to convert the array of tuples back to an array of dictionaries using this code:
let array = dict.map{[$0.0:$0.1]}
...but I'm trying to understand why map gives me tuples in the first place.