0
0
iOS Swiftmobile~10 mins

Sheet and fullScreenCover in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to present a sheet when the button is tapped.

iOS Swift
Button("Show Sheet") {
  showSheet = true
}
.sheet(isPresented: $[1]) {
  Text("Hello from Sheet")
}
Drag options to blanks, or click blank then click option'
AshowFullScreen
BisSheetVisible
CsheetVisible
DshowSheet
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that is not a binding boolean.
Forgetting the $ sign before the variable name.
2fill in blank
medium

Complete the code to present a fullScreenCover when the button is tapped.

iOS Swift
Button("Show Full Screen") {
  [1] = true
}
.fullScreenCover(isPresented: $showFullScreen) {
  Text("Hello Full Screen")
}
Drag options to blanks, or click blank then click option'
AshowSheet
BshowFullScreen
CisFullScreenVisible
DfullScreenActive
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name that does not match the binding.
Forgetting to set the variable to true on button tap.
3fill in blank
hard

Fix the error in the code to correctly dismiss the sheet.

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

  var body: some View {
    Button("Show Sheet") {
      showSheet = true
    }
    .sheet(isPresented: $showSheet) {
      Button("Dismiss") {
        [1] = false
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aself.showSheet
BisPresented
CshowSheet
DshowFullScreen
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to dismiss by setting a different variable.
Using 'self.showSheet' inside the closure without explicit self capture.
4fill in blank
hard

Fill both blanks to create a sheet that passes data and dismisses itself.

iOS Swift
struct DetailView: View {
  @Environment(\.[1]) var dismiss
  var message: String

  var body: some View {
    VStack {
      Text(message)
      Button("Close") {
        [2]()
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Adismiss
BpresentationMode
Cdismiss()
Attempts:
3 left
💡 Hint
Common Mistakes
Using presentationMode instead of dismiss in iOS 15+.
Not calling dismiss as a function.
5fill in blank
hard

Fill all three blanks to present a fullScreenCover with a dismiss button and pass a title.

iOS Swift
struct ContentView: View {
  @State private var showFullScreen = false

  var body: some View {
    Button("Open Full Screen") {
      [1] = true
    }
    .fullScreenCover(isPresented: $showFullScreen) {
      FullScreenView(title: [2], onDismiss: [3])
    }
  }
}

struct FullScreenView: View {
  var title: String
  var onDismiss: () -> Void

  var body: some View {
    VStack {
      Text(title)
      Button("Close") {
        onDismiss()
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AshowFullScreen
B"Welcome"
C{ showFullScreen = false }
DshowSheet
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable names.
Not passing a closure for onDismiss.
Using showSheet instead of showFullScreen.