A set stores unique values of the same type in a collection without a defined order. Let's look at a diagram:
In the preceding 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.
Before we create these sets, let's just create an empty set and see what that looks like:
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.
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>([])
Your code should now look like this:
This preceding immutable set has a data type of Int, but in the parentheses we pass an empty array literal when we used the brackets.