I got this error when try to run my code
=> "Value of type 'DismissAction' has no member 'wrappedValue'"
i was trying to learn to how go back to previous root without using back button of navigation bar because i planned to remove it but when i tried my code it doesn't run.
@Environment(\.dismiss) var presentationMode
var body: some View{
Button("dismiss"){
presentationMode.self.wrappedValue.dismiss()
}
.background(Color.teal)
.frame(width: 150, alignment: .leading)
}
thank you
CodePudding user response:
If you want to use presentationMode.self.wrappedValue.dismiss()
, you have to declare your @Enviroment as @Environment(\.presentationMode)
.
This error occurred because you are using the wrong type of dismiss().
Also, you could achieve this dismissing in a simpler way by using (\.dismiss)
type instead:
@Environment(\.dismiss) var dismiss //modified
var body: some View {
Button("dismiss") {
dismiss() //modified
}
}