SwiftUI NavigationLink implementation guide view state on deep link navigation
Can someone help me understand I'm optimizing some code but I'm sure I'm missing something obvious here, but I'm working with an scenario where a `NavigationLink` in my SwiftUI app is not updating the view state correctly when the app is opened via a deep link... The deep link is structured to navigate to a specific detail view of an item, but it seems the state does not reflect the expected values. Here's the relevant part of my code: ```swift struct ContentView: View { @State private var selectedItem: Item? var body: some View { NavigationView { List(items, id: \.$id) { item in NavigationLink(destination: DetailView(item: item), tag: item, selection: $selectedItem) { Text(item.name) } } } } } struct DetailView: View { var item: Item var body: some View { Text(item.details) } } ``` I've set up a deep link handler in my AppDelegate like this: ```swift func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { guard let itemId = url.queryParameters?['id'] else { return false } // Assuming `items` is accessible here if let item = items.first(where: { $0.id == itemId }) { DispatchQueue.main.async { self.selectedItem = item } } return true } ``` However, when I open the app using a URL like `myapp://item?id=123`, the `selectedItem` doesn't seem to update in the `ContentView`, and I remain on the main list without seeing the detail view. I've tried manually triggering a navigation update by calling `self.selectedItem = item` on the main thread, but it still doesn't reflect correctly. I've also ensured that the `selectedItem` is marked with `@State`, so it should trigger a re-render. The `List` should navigate to the `DetailView`, but it seems to be exploring in its previous state. Is there something I'm missing regarding state management or navigation handling in SwiftUI? Any insights would be greatly appreciated! I'm working on a API that needs to handle this. Has anyone else encountered this? This is happening in both development and production on Ubuntu 22.04. Thanks, I really appreciate it! This is part of a larger microservice I'm building. Any advice would be much appreciated.