Dictionary won't sort | Swift

I don't have much experience with Xcode and Swift, and I've had quite a number of issues; but this one left me puzzled.

 

For a task in class, we had to sort a dictionary by its values. I was successful with the sorting part, but it seems the sorted keys and values won't load back into the dictionary in the correct order.

Screen Shot 2018-02-05 at 9.08.35 AM.png

Here's a snippet of what I did (I set the keys and values into separate arrays for sorting then loaded them back in). Now, I know it's sorted because of the printing part of the loop.

Screen Shot 2018-02-05 at 9.12.38 AM.png

But when I print or call the captainGPAs, it's in its original order despite it being empty before the sort.

Screen Shot 2018-02-05 at 9.17.39 AM.png

 

If you have a solution to this issue, it would be greatly appreciated.


MacBook Air, macOS Sierra (10.12.6), Xcode v9.2, Swift
Has invited:

howapple - hello

Favor from:


Hello RoninTech,

A dictionary is an unordered collection. It can't be sorted. All you can do is sort the keys and access the values via that array of sorted keys.

To reply to a question, please Login or registered