Created
May 31, 2021 13:48
-
-
Save pilgwon/319ff93386cd659b26e358f5025409f7 to your computer and use it in GitHub Desktop.
NavigationLink TroubleShooting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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