Dictionaries
A dictionary is an unordered collection of values with each one accessed through a unique key. Let's look at the following diagram:
In our diagram, we have a dictionary of pizzas (Keys) with their prices (Values). In order to find something inside of a dictionary, we must look it up by its key. Let's look at a dictionary syntax:
Dictionary<Key, Value>
Creating a dictionary
The traditional way of creating a dictionary is to first declare it as a dictionary, and then, inside angle brackets, declare a type for the key and value. Let's create our first dictionary inside Playgrounds:
let dictFirstExample = Dictionary<String, String>()
The immutable dictionary we just created above has a data type of String for both its key and value. We have multiple ways to create a dictionary. Let's look at another by adding the following into Playgrounds:
let dictSecondExample = [String: Int]()
In this latest example, we created another immutable dictionary with its key...