From the course: Swift 5 Essential Training

Unlock the full course today

Join today to access over 24,100 courses taught by industry experts.

Core set methods

Core set methods

- [Instructor] Because sets only store unique values, there are a number of useful operations that we can perform with them, that would require a lot of hard coded logic if we were using something like an array or dictionary type. I've already copied over the activeQuests set from the last playground, so we can get right to work. Now, all the set operations we're going to use in this example need a second set to work against. So we're going to create a new variable here. We're going to call this completedQuests, type Set, let type inference do its thing. We're going to add some initial values. We're going to say, Big Boss, All-4-One, and The Hereafter. Perfect. Now the four fundamental set operations are intersection, difference, union, and subtraction, all of which pretty much do exactly what they sound like. So if we wanted to return a new set containing all the common values between both sets, we could declare a…

Contents