Understanding sets
Let's say you're writing a Movies app and you want to store a list of movie genres. You could do this with a set.
A set stores values in an unordered list. Here's what it looks like:
All values are of the same type.
If you create a set using the let
keyword, its contents cannot be changed after it has been created. If you want to change the contents after creation, use the var
keyword.
Let's look at how to work with sets. You'll create a set by assigning a value to it in the next section.
Creating a set
Imagine that you are creating a Movies app and you would like to store movie genres in your app. As you have seen for arrays and dictionaries, you can create a set by declaring it and assigning a new value to it. Add the following code to your playground and click the Play/Stop button to run it:
var movieGenres: Set = ["Horror", "Action", "Romantic...