Recall & Review
beginner
How do you create an empty set of integers in Swift?
Use
var numbers = Set<Int>() to create an empty set of integers.Click to reveal answer
beginner
What is the difference between a Set and an Array in Swift?
A Set stores unique values with no defined order, while an Array stores ordered values and can have duplicates.
Click to reveal answer
beginner
How do you add an element to a Swift set?
Use the
insert() method, for example: mySet.insert(5) adds the number 5 to the set.Click to reveal answer
intermediate
What does the
union() operation do on two Swift sets?It combines all unique elements from both sets into a new set, without duplicates.
Click to reveal answer
intermediate
How can you find common elements between two sets in Swift?
Use the
intersection() method to get a new set with elements found in both sets.Click to reveal answer
Which Swift code creates a set of strings?
✗ Incorrect
Option D correctly creates a Set of strings using Set<String> and array literal syntax.
What happens if you insert a duplicate element into a Swift set?
✗ Incorrect
Sets only store unique elements, so inserting a duplicate does nothing.
Which method returns elements in one set but not in another?
✗ Incorrect
subtracting() returns elements in the first set that are not in the second.How do you check if a Swift set contains a specific element?
✗ Incorrect
Use
contains() to check if an element is in the set.What is the result of
setA.union(setB)?✗ Incorrect
union() combines all unique elements from both sets.Explain how to create a set in Swift and add elements to it.
Think about starting empty and then putting things inside.
You got /3 concepts.
Describe the difference between union, intersection, and subtracting operations on sets.
Imagine mixing, matching, and removing items from two baskets.
You got /3 concepts.