0
0
Swiftprogramming~30 mins

Set creation and operations in Swift - Mini Project: Build & Apply

Choose your learning style9 modes available
Set creation and operations
📖 Scenario: You are organizing a small community event. You have lists of people who signed up for different activities. You want to use sets to manage these lists and find who is attending which activities.
🎯 Goal: Build a Swift program that creates sets of attendees for two activities, finds who is attending both activities, and who is attending only one.
📋 What You'll Learn
Create two sets with exact names and values
Create a variable for the union of the two sets
Create a variable for the intersection of the two sets
Print the union and intersection sets exactly
💡 Why This Matters
🌍 Real World
Managing event attendees and their participation in different activities helps organizers avoid duplicates and understand overlaps.
💼 Career
Set operations are useful in data processing, filtering unique items, and comparing groups in software development.
Progress0 / 4 steps
1
Create two sets of attendees
Create a set called activityA with these exact names: "Alice", "Bob", "Charlie". Then create another set called activityB with these exact names: "Bob", "Diana", "Eve".
Swift
Need a hint?

Use let to create sets with square brackets and commas between names.

2
Create a union set of all attendees
Create a variable called allAttendees that is the union of activityA and activityB.
Swift
Need a hint?

Use the union method on activityA with activityB as argument.

3
Create an intersection set of attendees in both activities
Create a variable called bothActivities that is the intersection of activityA and activityB.
Swift
Need a hint?

Use the intersection method on activityA with activityB as argument.

4
Print the union and intersection sets
Print the variables allAttendees and bothActivities exactly using two separate print statements.
Swift
Need a hint?

Use print(allAttendees) and print(bothActivities) to show the sets.