Member-only story

Sorting a Dictionary Doesn’t Make Sense

Wait, you can?

Steven Curtis
3 min readApr 19, 2021
Photo by Rachel on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 12.4, and Swift 5.3.2

Prerequisites

* You will be expected to be aware how to make a Single View Application in Swift, or use Playgrounds to do the same

Terminology

Dictionary: The association between keys and values (where all the keys are of the same type, and all values are of the same type)

The video

Watch me explain this myself: https://youtu.be/-NUzHVXL-FQ

The Dictionary

A Dictionary is a struct that provides fast access to the keys and values that it contains (great!). These might be known to you as hash tables or associated arrays if you are familiar with other languages.

Now the *issue* is that although the order of a Dictionary is stable while you are using it (for example during a particular execution), a Dictionary does not have a predictable ordering.

That is, a Dictionary is not an ordered collection (specifically, of course it has an order by definition…

--

--

No responses yet