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.
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.
But when I print or call the captainGPAs, it's in its original order despite it being empty before the sort.
If you have a solution to this issue, it would be greatly appreciated.
MacBook Air, macOS Sierra (10.12.6), Xcode v9.2, Swift
No result found
howapple - hello
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.