Sets
A set stores unique values of the same type in a collection without a defined order. Let's look at a diagram:
In the above diagram, we have two circles, both of which represent a set. On the left, we have Craig's favorite movies; and, on the right, we have Gabe's favorite movies.
Creating an empty set
Before we create these sets, let's just create an empty set and see what that looks like:
let movieSet = Set<String>()
In this first set, after the equals sign, we create the set and give it a data type of String. Then, we use the parentheses to initialize the set.
Creating a set with an array literal
Our first set was an empty String set, but we can create a set using an array literal. Let's add the following into Playgrounds:
let numberSet = Set<Int>([])
This above immutable set has a data type of Int; but, in the parentheses, we pass an empty array literal when we used the brackets.
Creating a mutable set
Now that we are familiar with the way sets are created...