Bird
0
0

Identify the issue in this SwiftUI code snippet:

medium📝 Debug Q6 of 15
iOS Swift - iOS Basics and Setup
Identify the issue in this SwiftUI code snippet:
struct ContentView: View {
  var body: some View {
    Button(action: {
      print("Tapped")
    })
  }
}
AButton cannot be used inside a View struct.
BThe print statement is invalid inside Button.
CThe body property should be a function, not a computed property.
DButton is missing a label view to display.
Step-by-Step Solution
Solution:
  1. Step 1: Check Button requirements

    A Button requires a label view to display on screen.
  2. Step 2: Analyze given code

    The Button has an action closure but no label view, causing a compile error.
  3. Final Answer:

    Button is missing a label view to display. -> Option D
  4. Quick Check:

    Button needs both action and label [OK]
Quick Trick: Button must have a label view [OK]
Common Mistakes:
  • Omitting label view
  • Misplacing action closure
  • Confusing print usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes