The issue isn't fixed and still can be represented on iOS 18.0
The solution of @kh_bb helps for the most of cases but the issue can be representated in some specific cases.
@cutecutealien it didn't help me, unfortunately. Can you please send you example?
Post
Replies
Boosts
Views
Activity
@DTS Engineer The issue IS NOT fixed in Xcode 16 Beta 6 + iOS 18 Beta 7 and still persists :(
The issue IS NOT fixed in Xcode 16 Beta 6 + iOS 18 Beta 7.
@sjb_s thank you for your feedback.
You can see my code in the post above that contains the code that always fails (double-push always happens) and some explanation.
Also I created the Bug report with the full descriptions and steps how to reproduce this bug: https://feedbackassistant.apple.com/feedback/14743917
@DTS Engineer we really your help here please.
@DTS Engineer I created and sent Bug report in Feedback assistant: https://feedbackassistant.apple.com/feedback/14743917
Thank you.
@DTS Engineer I created and send Bug report in Feedback assistant: https://feedbackassistant.apple.com/feedback/14743917
@sjb_s @dderg @brebispanique @DTS Engineer
Here is the full code (a modification of @sjb_s 's example) that still DOESN'T work well.
The main reason is that navigationDestination is located in View extension. It is how it is designed in my real app where I have a single navigationDestination for the whole app and all possible routes inside it.
Everything works well in iOS 17.x with this approach, but still doesn't work well in iOS 18.0 Beta 5.
Any ideas?
import SwiftUI
class Item: Identifiable, Hashable {
var name: String
init(name: String) {
self.name = name
}
static func == (lhs: Item, rhs: Item) -> Bool {
lhs.name == rhs.name
}
func hash(into hasher: inout Hasher) {
hasher.combine(name)
}
}
class Model: ObservableObject {
@Published var path = [Item]()
}
struct ContentView: View {
var items = [
Item(name: "Item 1"),
Item(name: "Item 2"),
Item(name: "Item 3"),
]
@StateObject private var model = Model()
var body: some View {
TabView {
Text("Go to Tab 2")
.tabItem { Label("Tab 1", systemImage: "storefront") }
.tag("1")
tab2()
.tabItem { Label("Tab 2", systemImage: "globe") }
.tag("2")
}
}
@ViewBuilder
func tab2() -> some View {
NavigationStack(path: $model.path) {
List(items) { item in
NavigationLink(item.name, value: item)
}
.withAppRouter()
}
}
}
extension View {
func withAppRouter() -> some View {
navigationDestination(for: Item.self) { item in
DetailView(item: item)
}
}
}
struct DetailView: View {
var item: Item
var body: some View {
Text("Details...\(item.name)")
}
}
@DTS Engineer thank you for your answer.
But what I don't want to use the type-erased data representation and still want to use my custom data type. I need that for correct programmatic routing in my app and for understanding of the exact path of my current router.
There is an Apple's API for that so I expect to use my custom type.
It is still NOT FIXED in Xcode 16 beta 5 + iOS 18.0 beta 5 and the same issue happens.
Any plans to fix it? Thank you.
enum RouterDestination: Hashable {
case next
}
@brebispanique @sjb_s it is not fixed on my side, unfortunately. I can see the same issue on Simulator.
Do you test on a real device or simulator?
Could you please attach a full code of your solution so I'll be able to compile it and check?
I can confirm that the issue IS NOT fixed in iOS 18 beta 4 Simulator (22A5316j).
I also face similar issue and wrote about it in another post:
https://developer.apple.com/forums/thread/760041
I can confirm that the usage NavigationPath fixes this issue but the other issues appear. A views that weren't pushed appear in path and I have to pop the several times.
So it seems that the combination TabView + NavigationStack inside is buggy.
Two notes:
I tried to use iOS 17+ @Observable approach. It didn’t help.
Using @State var path: [RouterDestination] = [] directly inside View seems to help. But it is not what I want as I need this property to be @Published and located inside custom Router class where I can get an access to it, and use for programmatic navigation if needed.
I found a similar issue reported by other developers here: https://developer.apple.com/forums/thread/759542 so the problem really exists and seems to be a bug
@okla I have exactly the same problem and wrote about it here: https://developer.apple.com/forums/thread/736239
Can someone from Apple engineers help with this and confirm that it is a bug that will be fixed?