Bird
0
0

What is wrong with this SwiftUI view code?

medium📝 Debug Q7 of 15
iOS Swift - SwiftUI Basics
What is wrong with this SwiftUI view code?
struct TestView: View {
  var body: some View {
    VStack {
      Text("Line 1")
      Text("Line 2")
    }
  }

  var body: some View {
    Text("Duplicate")
  }
}
AVStack cannot contain multiple Text views
BDuplicate body property declarations cause a compile error
CText views must be inside a function, not a property
DNo error, last body overrides the first
Step-by-Step Solution
Solution:
  1. Step 1: Identify duplicate body properties

    The code declares body twice, which is not allowed in SwiftUI views.
  2. Step 2: Understand SwiftUI rules

    Only one body property is permitted; duplicates cause compilation errors.
  3. Final Answer:

    Duplicate body property declarations cause a compile error -> Option B
  4. Quick Check:

    One body property only = Duplicate body property declarations cause a compile error [OK]
Quick Trick: Only one body property per View allowed [OK]
Common Mistakes:
  • Declaring body twice
  • Thinking VStack limits Text views
  • Assuming last body overrides first

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes