How can a dictionary be sorted, by its keys, in the order listed in an array? See example:
Dictionary to sort:
var item = [
"itemName":"radio",
"description":"battery operated",
"qtyInStock":"12",
"countOfChildren":"5",
"isSerialized":"0"
]
Order in which the keys should be sorted:
let sortOrder = [
"itemName",
"qtyInStock",
"countOfChildred",
"description",
"isSerialized"
]
I have tried the following in Playground:
var sortedItem = Dictionary<String, String>()
for i in sortOrder {
sortedItem[i] = item[i]
}
While viewing the value history in Playground displays everything in the correct order, the resulting dictionary is in a seemingly random order.