- Published on
Dismiss a View in SwiftUI
- Authors
- Name
- Jenny Kim
Add these three lines to your view.
@Environment(\.dismiss)
private var dismiss
...
dismiss()
Example View:
struct ShouldDismissView: View {
@Environment(\.dismiss)
private var dismiss
var body: some View {
Button("Dismiss") {
dismiss()
}
}
}