NavigationStack and NavigationSplitView Runtime warnings

Overview:

When running the demo code presented in "The SwiftUI cookbook for navigation" (https://developer.apple.com/wwdc22/10054) I ran into some issues:

Runtime warnings:

2022-06-08 22:20:31.587169+0800 NavigationSplitViewDemo[17797:672165] [SwiftUI] A NavigationLink is presenting a value of type “Category” but there is no matching navigation destination visible from the location of the link. The link cannot be activated.
onChange(of: UpdateTrigger) action tried to update multiple times per frame.
2022-06-08 22:15:23.432289+0800 NavigationSplitViewDemo[17645:662571] [UIFocus] _TtGC7SwiftUI14_UIHostingViewGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__ implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.

Feedback filed:

FB10103041 and FB10104196

Answered by newwbee in 716228022

Based on the Apple Engineer's response this is a bug, I have also filed feedback and mentioned it.

Accepted Answer

Based on the Apple Engineer's response this is a bug, I have also filed feedback and mentioned it.

I had same error but in my own code and I wrote another feedback ticket for that: FB10260549 with my own sample project to reproduce it. I didn't look at the demo code but in my case its when you have a NavigationLink(value:) in a List with valid .navigationDestination modifier code but that is inside a destination view of a parent List with NavigationLinks that use the old style without values.

Confusion about NavigationSplitView

There seem to be 2 ways:

Not sure what is the correct approach, using NavigationLink seems to require navigationDestination but that doesn't sit well with NavigationSplitView as the destination view is specified part of the detail closure and repeating the code would be redundant.

Following the documentation (without NavigationLink):

Update NavigationAuthority bound selection tried to update multiple times per frame.
  • The other 2 warnings about navigationDestination and Focus are not thrown

I really wish someone from the Apple team could clarify on this, please.

Me too, Xcode 14 beta

2022-07-09 15:59:03.015247+0800 BarB[30014:522659] [UIFocus] UIPickerTableView implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.

2022-07-09 15:59:03.015440+0800 BarB[30014:522659] [UIFocus] UIPickerTableView implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.

I get the same console message. The only new method of NavigationLink that works with NavigationStack, at least for me, is the form.

NavigationLink 
     { MyDestinationView(data: data) } label: {
           MyRowView(data: data)
 }

However, I cannot go back in the navigation stack, only forward. No back buttons. But just this morning, I replaced NavigationStack with NavigationView and I had back buttons. I reworked all of my data to fit in the new form. I think that was a good thing anyway, so I want this to work. I could be messing up. Not sure. But with others having the same issue, it could be I'm doing this okay. We shall see.

NavigationStack - Works as expected

The following code works as expected

struct ContentView: View {
    
    @StateObject private var dataStore = DataStore()
    @State private var navigationPath = [Car]()
    
    var body: some View {
        NavigationStack(path: $navigationPath) {
            List {
                ForEach(dataStore.cars) { car in
                    NavigationLink(car.name, value: car)
                }
            }
            .navigationDestination(for: Car.self) { car in
                CarDetail(car: car,
                          navigationPath: $navigationPath)
            }
            .navigationTitle("Car List")
        }
    }
}

NavigationSplitView - Doesn't work on compact width (iPhone)

The problem with NavigationSplitView is that on iPhone (compact width - behaves like pushing views) the following happens:

  1. Select one cell and going into the detail view
  2. Press back to come parent view
  3. Select another cell, nothing happens, it just selects the cell but doesn't push to the detail view

I created a very simple project as follows.

NavigationLink("Go To Next View", value: "TheView")
         .navigationDestination(for: String.self) { val in
                Text("Value = \(val)")
         }

This example worked in the simple project. But when I put this into my app's project using NavigationStack, I navigated to the next view fine, but had no back button.

Same Xcode 14 beta 3

.navigationDestination should be placed inside the NavigationStack:

List {
  NavigationLink("Go to MyView", value: "MyView")
}

…

NavigationStack {
  Text("Home")
  .navigationDestination(for: String.self) { val in
    Text("View = \(val)")
  }
}

This works for me.

Yes, best to use the new APIs as suggested in https://developer.apple.com/wwdc22/10054

There is a bug (mentioned in my earlier post) with NavigationSplitView with the navigation on a single column, but this is marked as a known issue in iOS 16 beta (3, 4) release notes.

For three column layouts, try setting the selected state of the middle column to nil onDisappear as done in ThreeColumnContentView within https://developer.apple.com/documentation/swiftui/bringing_robust_navigation_structure_to_your_swiftui_app

@justletmeintotheforum Thanks a ton!!!!! Made my day! Wow

Is this a must? Or is this workaround for a bug?

Xcode 14.0 beta 5 (14A5294e) seem to have fixed my issues with NavigationSplitView

  • Fixed - Warnings
  • Fixed - Selection of cell not happening (2nd time) in compact mode (For 3 column layout) - so no need to set the selected state of the middle column to nil onDisappear

Hopefully it has fixed your issues as well, if not please file a feedback

NavigationStack and NavigationSplitView Runtime warnings
 
 
Q