0
0
iOS Swiftmobile~20 mins

Sheet and fullScreenCover in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modal Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
Difference in dismissal behavior between Sheet and fullScreenCover

In SwiftUI, what is the main difference in how a Sheet and a fullScreenCover are dismissed by default?

ABoth Sheet and fullScreenCover can be dismissed by swiping down by default.
BSheet can be dismissed by swiping down, but fullScreenCover requires explicit dismissal.
CfullScreenCover can be dismissed by swiping down, but Sheet requires explicit dismissal.
DNeither Sheet nor fullScreenCover can be dismissed by swiping down.
Attempts:
2 left
💡 Hint

Think about the default user interaction for modal views in iOS.

navigation
intermediate
2:00remaining
State variable usage for presenting Sheet vs fullScreenCover

Which SwiftUI state variable type is best suited to control the presentation of a Sheet or fullScreenCover when you want to present a modal based on a Boolean condition?

A@State Bool variable toggled true/false to show or hide the modal.
B@State Array variable holding multiple modal views.
C@State Int variable counting how many times modal was shown.
D@State String variable holding the modal content title.
Attempts:
2 left
💡 Hint

Think about what type controls visibility: true means visible, false means hidden.

lifecycle
advanced
2:00remaining
Effect of dismissing a fullScreenCover on parent view lifecycle

When a fullScreenCover is dismissed in SwiftUI, what happens to the parent view's lifecycle?

AThe parent view pauses and resumes animations but resets state.
BThe parent view reloads completely and resets all its state variables.
CThe parent view is destroyed and recreated from scratch.
DThe parent view remains active and does not reload or reset its state.
Attempts:
2 left
💡 Hint

Consider how modal presentation affects the underlying view in SwiftUI.

📝 Syntax
advanced
2:30remaining
Correct syntax for presenting a Sheet with data binding

Which SwiftUI code snippet correctly presents a Sheet that passes a binding to a detail view?

iOS Swift
struct ContentView: View {
  @State private var showSheet = false
  @State private var selectedName = ""

  var body: some View {
    Button("Show Sheet") {
      showSheet = true
    }
    .sheet(isPresented: $showSheet) {
      DetailView(name: $selectedName)
    }
  }
}

struct DetailView: View {
  @Binding var name: String
  var body: some View {
    TextField("Enter name", text: $name)
  }
}
A.sheet(isPresented: showSheet) { DetailView(name: $selectedName) }
B.sheet(showSheet) { DetailView(name: selectedName) }
C.sheet(isPresented: $showSheet) { DetailView(name: $selectedName) }
D.sheet(isPresented: $showSheet) { DetailView(name: selectedName) }
Attempts:
2 left
💡 Hint

Remember to pass bindings with a $ prefix and use the correct parameter name.

🔧 Debug
expert
3:00remaining
Why does fullScreenCover not dismiss when swiping down?

Given this SwiftUI code, why does the fullScreenCover not dismiss when the user swipes down?

struct ContentView: View {
  @State private var showModal = true

  var body: some View {
    Button("Show") { showModal = true }
      .fullScreenCover(isPresented: $showModal) {
        ModalView()
      }
  }
}

struct ModalView: View {
  var body: some View {
    Text("Modal")
  }
}
AfullScreenCover does not support swipe-to-dismiss by default; dismissal must be handled programmatically.
BThe @State variable showModal is not toggled to false inside ModalView, so it never dismisses.
CThe Button is inside the fullScreenCover, blocking swipe gestures.
DThe ModalView must have a NavigationView to enable swipe-to-dismiss.
Attempts:
2 left
💡 Hint

Think about default user interactions for fullScreenCover modals.