I tried to use navigationstack, and it works. but couldn't print the path, and with the message: " NavigationPath(_items: SwiftUI.NavigationPath.(unknown context at $7ff84b690a28).Representation.eager([SwiftUI.(unknown context at $7ff84b6907f0).CodableItemBox<Swift.String>]), subsequentItems: [], iterationIndex: 0). "
`import SwiftUI
var toDos: [String] = [ "list1", "list2", "list3" ]
struct ContentView: View { @State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List {
ForEach(toDos, id:\.self) { toDo in
Button(action: {
path.append(toDo)
print(path)
}, label: {
Text("go to " + toDo)
})
}
}
.navigationDestination(for: String.self) { toDo in
Text("page for " + toDo)
}
}
}
}
#Preview { ContentView() }` I tried navigationlink and simulator still works fine, but cannot print anything of path
If this is just for debugging purposes, you can use
dump(path)
instead ofprint(path)
.This gives an output like this:
The actual elements in the path are listed under
▿ eager: 1 element
. There are quite a lot of noise in the output, but at least you do see the elements being printed.If the
NavigationPath
only consists ofCodable
elements, you can encode the path to a JSON string.This gives an output like this: