0
0
Swiftprogramming~15 mins

Zip for combining sequences in Swift - Mini Project: Build & Apply

Choose your learning style9 modes available
Zip for combining sequences
📖 Scenario: Imagine you are organizing a small event and you have two lists: one with the names of guests and another with their favorite drinks. You want to pair each guest with their favorite drink to prepare the serving list.
🎯 Goal: Build a Swift program that uses zip to combine two arrays: one with guest names and one with their favorite drinks, then print each guest with their drink.
📋 What You'll Learn
Create an array called guests with these exact names: "Alice", "Bob", "Charlie"
Create an array called drinks with these exact drinks: "Coffee", "Tea", "Juice"
Use zip to combine guests and drinks
Use a for loop with variables guest and drink to iterate over the zipped pairs
Print each guest and their favorite drink in the format: "Alice likes Coffee"
💡 Why This Matters
🌍 Real World
Combining related lists like names and preferences is common in event planning, data processing, and user interface development.
💼 Career
Understanding how to combine sequences efficiently is useful for software developers working with collections, data transformation, and UI data binding.
Progress0 / 4 steps
1
Create the guests array
Create an array called guests with these exact names: "Alice", "Bob", "Charlie"
Swift
Need a hint?

Use square brackets [] to create an array and separate names with commas.

2
Create the drinks array
Create an array called drinks with these exact drinks: "Coffee", "Tea", "Juice"
Swift
Need a hint?

Use the same array syntax as for guests.

3
Use zip to combine guests and drinks
Use zip to combine guests and drinks into a variable called guestDrinkPairs
Swift
Need a hint?

Use zip(guests, drinks) and assign it to guestDrinkPairs.

4
Print each guest with their favorite drink
Use a for loop with variables guest and drink to iterate over guestDrinkPairs. Inside the loop, print each guest and their drink in the format: "Alice likes Coffee"
Swift
Need a hint?

Use string interpolation with \(variable) inside print.