79151484

Date: 2024-11-02 20:01:40
Score: 0.5
Natty:
Report link

This has been answered multiple times but never afais gives the response starting by pressing a Button to get to the next View. Adding this approach just in case someone ends up (just like me) on a Google search that has this answer as one the top links.

This approach is a combination of @State variable on the Initial View and the same variable as @Binding in the Ending View. You can always add a "Back" button on the ending View to return to the original.

struct InitialView: View {   
    @State private var isEndingViewActive = false   
    HStack {
            var body: some View {
                if isEndingViewActive {
                    EndingView(isEndingViewActive: $isEndingViewActive)
                } else {
                Button(“Going to End View”) {
                   isEndingViewActive = true
                }
            }
        }
    }
}

struct EndingView: View {    
    @Binding private var isEndingViewActive: Bool
    HStack {   
            var body: some View {
                Button(“Going Back to Initial View”) {
                isEndingViewActive = false
                }
        }
    }
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @State
  • User mentioned (0): @Binding
  • Low reputation (1):
Posted by: Norberto Carbonell