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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.