SwiftUI NavigationView not retaining state after programmatic pop on iOS 17
I recently switched to I'm converting an old project and I'm reviewing some code and I'm relatively new to this, so bear with me... I'm facing an issue with `NavigationView` in SwiftUI where the navigation state is not retained after programmatically popping a view. My app has a series of navigable views, and I'm using a button to pop the current view. When I pop the view using a `@Binding` variable to control the navigation, it seems to reset the entire state of the previous view instead of retaining it. Hereβs a simplified version of my code: ```swift struct ParentView: View { @State private var isNavigating = false @State private var data: String = "Initial data" var body: some View { NavigationView { VStack { Text(data) NavigationLink(destination: ChildView(data: $data), isActive: $isNavigating) { Text("Go to Child") } Button(action: { isNavigating = false }) { Text("Back") } } } } } struct ChildView: View { @Binding var data: String var body: some View { VStack { Text("Child View") Button(action: { data = "Updated Data" // Pop action handled elsewhere }) { Text("Update Data") } } } } ``` When I press the "Update Data" button in the `ChildView`, the data updates correctly. However, when I press the "Back" button, the `ParentView` resets the `data` back to "Initial data" instead of keeping it as "Updated Data". Iβve tried using `@StateObject` for the data model, but it didn't solve the issue. I also confirmed that Iβm not directly re-initializing `ParentView` on pop. Has anyone had similar issues or found a workaround? Is there a best practice for retaining state in SwiftUI when navigating back? Iβm using Xcode 15.0 and targeting iOS 17. For context: I'm using Swift on Ubuntu. I'd really appreciate any guidance on this. This is my first time working with Swift LTS. What am I doing wrong? I recently upgraded to Swift 3.10. Any advice would be much appreciated. I'm working in a Windows 10 environment. What are your experiences with this? My team is using Swift for this mobile app. What am I doing wrong?