Bird
0
0

Why might you choose to use a tuple with named elements as a function return type in Swift instead of a struct?

hard📝 Conceptual Q10 of 15
Swift - Functions
Why might you choose to use a tuple with named elements as a function return type in Swift instead of a struct?
ATuples allow stored properties and methods like structs
BTuples provide a lightweight way to return multiple values without defining a new type
CTuples enforce type safety better than structs
DTuples can be extended with protocols like structs
Step-by-Step Solution
Solution:
  1. Step 1: Understand tuples vs structs

    Tuples are simple, quick containers for multiple values without extra code.
  2. Step 2: Compare features

    Structs support methods and protocols; tuples do not. Tuples are lightweight and convenient.
  3. Final Answer:

    Tuples provide a lightweight way to return multiple values without defining a new type -> Option B
  4. Quick Check:

    Tuples = lightweight multiple values [OK]
Quick Trick: Use tuples for quick multiple returns, structs for complex data [OK]
Common Mistakes:
  • Thinking tuples have methods
  • Confusing tuples with structs
  • Assuming tuples support protocols

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes