From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Working with sets

Working with sets

- [Instructor] One of the most underrated collection types is sets. Sets are an unordered collection with unique values. Let's take a look at what you can do with sets. Download the exercise file, and you'll find I created a playground with a struct called pizza here. I've made several pizzas for you, which you can see down here. Currently this is all arrays, but does it have to be arrays? Ask yourself three questions. Do I need ordered values? Do I need unique values? And do I need access directly to any value? A pizza is a good example of where a set works well. An ingredient is just an ingredient. There's no good reason to list it twice. And it also has no particular order for toppings. I don't need to access only one ingredient. That's a set. Sets are stored and accessed more efficiently than arrays or dictionaries. So if you can use a set, do so. Let's convert this struct to sets. For the two constants on…

Contents