Bird
0
0

Which of the following is the correct syntax to present a sheet in SwiftUI?

easy📝 Syntax Q12 of 15
iOS Swift - Navigation
Which of the following is the correct syntax to present a sheet in SwiftUI?
A.fullScreenCover(showModal) { Text("Hello") }
B.sheet(isPresented: $showModal) { Text("Hello") }
C.sheet(showModal) { Text("Hello") }
D.fullScreenCover(isPresented: showModal) { Text("Hello") }
Step-by-Step Solution
Solution:
  1. Step 1: Check correct parameter usage

    The sheet modifier requires a binding boolean with isPresented: to control showing.
  2. Step 2: Validate closure syntax

    The closure provides the view to present, here Text("Hello").
  3. Final Answer:

    .sheet(isPresented: $showModal) { Text("Hello") } -> Option B
  4. Quick Check:

    Correct syntax uses isPresented with $ binding [OK]
Quick Trick: Use .sheet(isPresented: $var) { View } for sheets [OK]
Common Mistakes:
  • Omitting $ for binding variable
  • Using wrong parameter name
  • Confusing sheet and fullScreenCover syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes