The navigationDestination is being called a single time when using an array of type (ie: [String]
) but multiple times when using NavigationPath
after an append.
Check it with a breakpoint on Text(string)
and switching the path types.
Tested with:
- iOS 16.1 - Xcode 14.0 & 14.1
- iOS 16.4.1 - Xcode 14.3
- iOS 16.5 - Xcode 14.3
Code:
import SwiftUI
struct ContentView: View {
@State private var path = NavigationPath()
// @State private var path = [String]()
var body: some View {
NavigationStack(path: $path) {
VStack {
Button("append") {
path.append("string")
}
}
.navigationDestination(for: String.self) { string in
Text(string) // <--- breakpoint here
}
}
}
}