Skip to content

Instantly share code, notes, and snippets.

@pilgwon
Created May 31, 2021
Embed
What would you like to do?
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