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 - Swift Tutorial
From the course: Swift 5 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Gathering inventory with collections24s
-
(Locked)
Swift arrays4m 27s
-
(Locked)
Core array methods6m 47s
-
(Locked)
Swift dictionaries5m 39s
-
Core dictionary methods7m 6s
-
(Locked)
Working with sets4m 12s
-
(Locked)
Core set methods3m 35s
-
(Locked)
Swift tuples5m 10s
-
Challenge: Merchant shop32s
-
(Locked)
Solution: Merchant shop5m 19s
-
(Locked)
-
-
-
-
-