5

I have a TabView and each Tab has it's own NavigationPath which I am handling inside an ObservableObject.

@MainActor final class Router: ObservableObject {
    @Published var homeNavigationPath = NavigationPath()
    @Published var searchNavigationPath = NavigationPath()
    @Published var notificationsNavigationPath = NavigationPath()
    @Published var profileNavigationPath = NavigationPath()
}

I am doing this so each Tab can PopToRoot of it's own accord. Everything seems to be working great, however I get the following message in the Console...

Update NavigationAuthority bound path tried to update multiple times per frame.

Does anyone know what this means? Am I doing something wrong or is it perfectly fine to have multiple NavigationPaths like this?

Timmy
  • 4,098
  • 2
  • 14
  • 34
Dan
  • 543
  • 2
  • 13
  • 1
    It's ok to have multiple paths but unless you are trying to persist them to disk they shouldn't be in an object. Instead put them as @State in each Tab. – malhal Nov 14 '22 at 16:50
  • Hey @malhal I have put them in an ObservableObject so I can push/pop/dismiss from the correct Path depending on the selected tab. These tutorials lead me to this approach... https://www.youtube.com/watch?v=WSmzhPzbCig&t=833s , https://www.youtube.com/watch?v=pwP3_OX2G9A&t=1147s – Dan Nov 14 '22 at 20:57
  • 1
    I think it's best to use SwiftUI as designed, with value types and state/binding instead of global objects. – malhal Nov 14 '22 at 21:13
  • @Dan I was having the same issue, in my case using code based on this link: https://notificare.com/blog/2022/11/25/a-better-tabview-in-swiftui/ (it is really nice and explains how to pop-to-root and scroll to the top in a `TabView` on subsequent taps). Once I moved the individual paths out of the `@ObservableObject` to separate `@State` variables, those warnings went away. – koen Jan 28 '23 at 21:03
  • See my solution here: https://stackoverflow.com/questions/75076596/swiftui-tabview-run-code-in-subview-after-sequential-taps/75276153#75276153 – koen Jan 29 '23 at 15:39
  • I have the same issue, but it seems doesn't affect anything in my app. I ran Instruments for SwiftUI to see the activity. But everything is normal, without any unnecessary updates. – adri567 Jan 30 '23 at 22:29

0 Answers0