Sets

A set stores unique values of the same type in a collection without a defined order. Let's look at a diagram:

Sets

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>()
Creating an empty set

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 ...

Get iOS 10 Programming for Beginners now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.