3

I have a segmented picker on my main page allowing the user to select between views to be loaded into that main view. Each of those views has a NavigationStack with a path. Moving between them results in "Update NavigationAuthority bound path tried to update multiple times per frame." being thrown. Functionality still works as expected.

Main View

struct ContentView: View {
    @StateObject private var firstNavigation = NavigationStore()
    @StateObject private var secondNavigation = NavigationStore()
    
    enum ViewsOptions: String, CaseIterable { case First, Second, Other }
    @State private var selectedView: ViewsOptions = .First
    
    var body: some View {
        VStack {
            switch selectedView {
            case .First:
                NavigationStack(path: $firstNavigation.path) {
                    Text("First")
                }
            case .Second:
                NavigationStack(path: $secondNavigation.path) {
                    Text("Second")
                }
            case .Other:
                NavigationStack {
                    Text("others")
                }
            }
            Spacer()
            Picker(selection: $selectedView,
                   label: Text("Selection")) {
                ForEach(ViewsOptions.allCases, id: \.self) { Text($0.rawValue) }
            }
                   .pickerStyle(.segmented)
        }
    }
}

NavigationStore is a simple ObservableObject with a NavigationPath as I'll want to pass it to inner views to append values to the path.

class NavigationStore: ObservableObject {
    @Published var path = NavigationPath()
}

Behaviour: clicking into Other(navigationStack without path) doesn't result in error. Moving back and loading a NavigationStack(path:...) always result in error being thrown once. "Update NavigationAuthority bound path tried to update multiple times per frame."

Setting a breakpoint on NavigationStore shows it being repeatedly hit. Removing @Published reduces this, but the error keeps popping up. Behaviour remains the same.

Using @State private var firstNavigation = NavigationPath() does not produce the error, but now I can't manipulate the value on the inner views.

1
  • 1
    The issue is with the ObservableObject part. if you swift to a State the warning goes away. On the Apple Developer forums there is a mention of a "fix" that may be coming in a future release Mar 21, 2023 at 16:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.