Iterating over a set

You can use a for-in loop to iterate over every item in a set. Type in and run the following code:

// Iterating over a set
for genre in movieGenres {
print(genre)
}

You should see each set item in the Debug area. Since sets are unsorted, you may get the results in a different order when you run this code again.

In the next section, you will learn about the various operations that you can do with sets in Swift.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.182.45