Xcode 16 NavigationStack using environment variable

Hello,

My app worked perfectly using Xcode 15.4. After updating to Xcode 16, my NavigationStack started to present the same screen twice using the following code:

@EnvironmentObject private var pathSports: NavigationRouteManager

var body: some View {

NavigationStack(path: $pathSports.path) { .... } .environmentObject(pathSports) }

NavigationRouteManager:

import Foundation import SwiftUI

class NavigationRouteManager: ObservableObject {

@Published var path = NavigationPath()

func jumpToRootView() {
    path = NavigationPath()
}

}

I have had to change it to the following code for just a single screen to be displayed.

@State private var pathSports: NavigationPath = NavigationPath()

var body: some View {

    NavigationStack(path: $pathSports) {
    ....
    }

} Have others experienced this same problem, or is it just me?

Many thanks.

Answered by MSans in 807300022

It is not just you. There are a few threads here talking about this including https://developer.apple.com/forums/thread/759542.

There is the issue you mentioned and another that causes the “back” navigation to display views that were previously in the NavigationPath stack, but shouldn’t be at the time they are displayed. Specifically within tabs.

Developers on that thread mention that the latest beta for 18.1 appears to fix the issue and also provide a couple of workarounds for 18.0.

What I mean by displayed the same screen twice, when I clicked on a NavigationLink it would display the screen, then 1/4 of a second later, the same screen was presented again. When I selected '<Back', I would have to press it twice to return to my same screen. This also happened on child screens also..

Accepted Answer

It is not just you. There are a few threads here talking about this including https://developer.apple.com/forums/thread/759542.

There is the issue you mentioned and another that causes the “back” navigation to display views that were previously in the NavigationPath stack, but shouldn’t be at the time they are displayed. Specifically within tabs.

Developers on that thread mention that the latest beta for 18.1 appears to fix the issue and also provide a couple of workarounds for 18.0.

Xcode 16 NavigationStack using environment variable
 
 
Q