NavigationSplitView doesn't work using enum with associated type

I have the following model in place for navigating to various pages:

enum Destination: Hashable {
  case today
  case activity
  case settings(path: SettingsPath? = nil)
  case project(project: ProjectItem? = nil)
  
  enum SettingsPath: Hashable {
    case cycles
    case donations

  }

}

In an ObservableObject, I'm using

@Published var sidebarDestination: Destination? = .today

And then in various NavigationLink buttons, I'm using the following initializer -

 NavigationLink(value: NavigationModel.Destination.activity...

In the detail section of my NavigationSplitView I'm using a switch like so

detail: {
      if let destination = navigationModel.sidebarDestination {

        switch destination {
        case .today:
            TodayView()
        case .project(let project):
          // FIXME: Why is the detail view not updating?

            if let selectedProject = project {
              ProjectDetailView(project: selectedProject)
            } else {
              EmptyView()
            }
...

I've noticed that the pages with an enum case with an associated value are not updating correctly - the title on the page will update, but none of the other content. The pages with an enum case without an associated type seem to work just fine.

All of this is using an iPad - the larger screen sizes

Is this a bug?

  • I have also tried iOS 16.1 and it still doesn't work there either

Add a Comment

Replies

It looks like the problem was actually to do with my viewModel not getting correctly re-initialized as it should have inside the NavigationSplitView. After fixing that part, this is now working fine.