Recall & Review
beginner
What is a tuple in Swift?
A tuple is a simple way to group multiple values into one compound value. Each value can be of any type, and the tuple can hold different types together.
Click to reveal answer
beginner
How do you create a tuple with a name and age in Swift?
You can create it like this: <pre>let person = (name: "Alice", age: 30)</pre> This groups the name and age together with labels.Click to reveal answer
beginner
How do you access values inside a tuple?
You can access values by their position or by their label if named. For example:
person.nameor
person.0.
Click to reveal answer
beginner
Can tuples hold different types of values?
Yes! Tuples can hold values of different types together, like a String and an Int in the same tuple.
Click to reveal answer
intermediate
What is a practical use of tuples in Swift?
Tuples are useful to return multiple values from a function or to group related values without creating a full struct or class.
Click to reveal answer
How do you declare a tuple with two values: an Int and a String?
✗ Incorrect
Tuples use parentheses () to group values, so (42, "Hello") is correct.
How do you access the second value in a tuple named 'data' without labels?
✗ Incorrect
Tuple elements are accessed by dot and index starting at 0, so data.1 accesses the second value.
Which of these is a valid tuple with named elements?
✗ Incorrect
Tuples with named elements use parentheses and labels like (x: 10, y: 20).
Can a tuple hold a String, an Int, and a Bool together?
✗ Incorrect
Tuples can hold different types together, so a String, Int, and Bool can be grouped.
What is a common use of tuples in Swift functions?
✗ Incorrect
Tuples are often used to return multiple values from a function in a simple way.
Explain what a tuple is and how you can use it to group values in Swift.
Think about how you can put different things together in one box.
You got /4 concepts.
Describe how tuples can help when returning multiple values from a function.
Imagine a function giving you more than one answer at once.
You got /4 concepts.