Swift provides a third collection type called Set. Set is not frequently used, purely by convention, but we do not think that this should be the case. This chapter will introduce Set and show off some of its unique advantages.
What Is a Set?
A Set is an unordered collection of distinct instances.
This definition sets it apart from an Array, which is ordered and can accommodate repeated values.
For example, an array could have the following content:
[2,2,2,2], but a set cannot.
A Set has some strong similarities to a Dictionary, but is also a little different. Like Dictionary, a set’s values are unordered within the collection. Similar to the requirement that a dictionary’s keys must be unique, Set does not ...