11 Sets
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access