Is there any built-in way to create an ordered map in Swift 2? Arrays [T]
are sorted by the order that objects are appended to it, but dictionaries
Here's what I did, pretty straightforward:
let array = [
["foo": "bar"],
["foo": "bar"],
["foo": "bar"],
["foo": "bar"],
["foo": "bar"],
["foo": "bar"]
]
// usage
for item in array {
let key = item.keys.first!
let value = item.values.first!
print(key, value)
}
Keys aren't unique as this isn't a Dictionary
but an Array
but you can use the array keys.