Bird
0
0

Why does the body property in SwiftUI use some View as its return type instead of a concrete type?

hard📝 Conceptual Q10 of 15
iOS Swift - SwiftUI Basics
Why does the body property in SwiftUI use some View as its return type instead of a concrete type?
ATo allow flexibility in returning different view types while hiding implementation details
BBecause SwiftUI does not support concrete types
CTo improve runtime performance by avoiding type checking
DBecause body can return multiple views at once
Step-by-Step Solution
Solution:
  1. Step 1: Understand opaque return types

    some View is an opaque type that hides the exact view type but guarantees it conforms to View.
  2. Step 2: Reason why this is used

    This allows the body to return different view types without exposing implementation details, improving flexibility.
  3. Final Answer:

    To allow flexibility in returning different view types while hiding implementation details -> Option A
  4. Quick Check:

    some View = opaque type for flexibility [OK]
Quick Trick: some View hides exact view type for flexibility [OK]
Common Mistakes:
  • Thinking SwiftUI disallows concrete types
  • Believing some View improves runtime speed
  • Assuming body returns multiple views directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes