As has already been answered, the point of a dictionary is that it is not sorted. There are three types of collections in Swift (and Objective-C)
An array is an ordered list of items. Use this when the order of the items is important.
A dictionary is an unordered collection of keys and values. Use this when you want to efficiently retrieve a value based on a key.
A set is a bag of unordered, unique items. Use this when you want to have a collection of unique items in no particular order.
For your case it seems that the ordering is what is important to you, but you want to store some kind of pair of values. Perhaps what you should be looking at is using an array of tuples:
something like this, maybe
let dataPoints = [("A", 1), ("B", 2), ("C", 3)]
for (letter, number) in dataPoints {
print("\(letter), \(number)")
}
which outputs
A, 1
B, 2
C, 3
Alternatively
If you don't know about the order of the items before their creation, but there is a natural ordering based on the keys, you could do something like this:
let dict = [
"A" : 1,
"B" : 2,
"C" : 3
]
for key in dict.keys.sort() {
guard let value = dict[key] else { break }
print("\(key), \(value)")
}
In this case you get an array of keys with their default sort order (you can use a different sort function if you have other requirements) and output the key values based on that sorted order.