Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created August 21, 2023 01:11
Show Gist options
  • Save foxicode/90795f7bbdff46ef13b98e236fb297d1 to your computer and use it in GitHub Desktop.
Save foxicode/90795f7bbdff46ef13b98e236fb297d1 to your computer and use it in GitHub Desktop.
NavigationStack SwiftUI example
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
List {
NavigationLink("Success", value: Target.successScreen)
NavigationLink("Error", value: Target.errorScreen)
}
.navigationDestination(for: Target.self) { target in
switch target {
case .successScreen:
SuccessView()
case .errorScreen:
ErrorView()
}
}
}
}
}
struct SuccessView: View {
var body: some View {
Text("Success. Yaaaay!")
}
}
struct ErrorView: View {
var body: some View {
Text("Error. Ooops...")
}
}
enum Target {
case successScreen
case errorScreen
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment