I need to push to other view controller when I get error from API call. All SwiftUI examples push are using navigation view and navigation link. I can't seem to make it work to push without action button.
You can use the isActive parameter of NavigationLink to bind a property and trigger the push changing the property value to true:
I'm using a Button action to change the value but you can do it in the error handling for example.
Code Block swift struct ContentView: View { @State private var isActive = false var body: some View { NavigationView { VStack { Button("Present") { isActive = true } NavigationLink(destination: Color.red, isActive: $isActive) { } } } } }
I'm using a Button action to change the value but you can do it in the error handling for example.