Bird
0
0

Identify the error in this SwiftUI code that tries to present a full screen cover:

medium📝 Debug Q14 of 15
iOS Swift - Navigation
Identify the error in this SwiftUI code that tries to present a full screen cover:
struct ContentView: View {
  @State var showFullScreen = false
  var body: some View {
    Button("Open") {
      showFullScreen = true
    }
    .fullScreenCover(isPresented: showFullScreen) {
      Text("Full Screen")
    }
  }
}
AState variable must be private.
BfullScreenCover cannot be used with Text views.
CMissing $ before showFullScreen in isPresented binding.
DButton label must be a View, not a String.
Step-by-Step Solution
Solution:
  1. Step 1: Check isPresented parameter

    The isPresented parameter requires a binding, so it must be $showFullScreen, not showFullScreen.
  2. Step 2: Confirm other code parts

    Using Text inside fullScreenCover is valid, and Button label can be a String.
  3. Final Answer:

    Missing $ before showFullScreen in isPresented binding. -> Option C
  4. Quick Check:

    Binding needs $ prefix [OK]
Quick Trick: Use $ for binding variables in isPresented [OK]
Common Mistakes:
  • Forgetting $ for binding
  • Thinking fullScreenCover needs complex views
  • Assuming Button label can't be String

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes