Skip to content

Instantly share code, notes, and snippets.

@nbhasin2
Created April 3, 2023 00:17
Show Gist options
  • Save nbhasin2/791ea6e0a89ea74d2582dea150a5cd28 to your computer and use it in GitHub Desktop.
Save nbhasin2/791ea6e0a89ea74d2582dea150a5cd28 to your computer and use it in GitHub Desktop.
NavigationStack: NavStackValueBasedContentView Example
struct NavStackValueBasedContentView: View {
let carTypes: [CarType]
let cars: [Car]
let viewType: ViewType = .navigationStackValueBasedView
var body: some View {
NavigationStack {
List {
Section("Car Type") {
ForEach(carTypes) { carType in
NavigationLink(value: carType) {
Text(carType.rawValue)
}
}
}
Section("Cars") {
ForEach(cars) { car in
NavigationLink(car.rawValue, value: car)
}
}
}
.navigationTitle("Car Selector")
.navigationDestination(for: CarType.self) { carType in
CarTypeView(carType: carType)
}
.navigationDestination(for: Car.self) { car in
CarDetailView(car: car)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment