logo
Published on

Dismiss a View in SwiftUI

Authors
  • avatar
    Name
    Jenny Kim
    Twitter

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()
        }
    }
}