Skip to content

Instantly share code, notes, and snippets.

@pilgwon
Created May 31, 2021 13:48
Show Gist options
  • Save pilgwon/319ff93386cd659b26e358f5025409f7 to your computer and use it in GitHub Desktop.
Save pilgwon/319ff93386cd659b26e358f5025409f7 to your computer and use it in GitHub Desktop.
NavigationLink TroubleShooting
import SwiftUI
enum SideMenu: String, CaseIterable {
case first
case second
case third
case fourth
case fifth
var id: String { "\(self)" }
var color: Color {
switch self {
case .first:
return Color.red
case .second:
return Color.orange
case .third:
return Color.yellow
case .fourth:
return Color.green
case .fifth:
return Color.blue
}
}
}
struct ContentView: View {
@State var showingDetailView: SideMenu?
var sideMenu: some View {
VStack {
ForEach(SideMenu.allCases, id: \.id) { menu in
NavigationLink(
destination: menu.color
.navigationTitle("\(menu.rawValue)"),
tag: menu,
selection: $showingDetailView,
label: {
Text("\(menu.rawValue)")
}
)
}
}
}
var body: some View {
NavigationView {
sideMenu
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment