I have NavigationStack with NavigationPath:
...
@State var path = NavigationPath()
...
var body: some View {
NavigationStack(path: $path) {
VStack() {
MyView() {
path.append("Edit")
}
}
.navigationDestination(for: String.self) { view in
if view == "Edit" {
EditView {
path.removeLast()
}
}
}
}
struct EditView: View {
var backAction: (() -> (Void))?
var body: some View {
VStack() {
Text("Edit")
}
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
backAction?()
} label: {
Image("backArrow")
}
}
}
The app is crashing on path.removeLast()
with:
EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
How should I implement the navigation with NavigationPath?