O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 content [2,2,2,2], but a set cannot.

A Set has some similarities to a Dictionary, but it is also a little different. Like a 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 allow repeated ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required