EXPECTED RESULTS
When the app launches, I would expect the List selects the initial row matching the @Binding that's passed in.
ACTUAL RESULTS
When the app launches, The List has no initial selected row until the user taps a row.
I'd like for the user to launch into the app with a Sidebar List row already selected, similar to the way the Shortcuts app does when launched. How do I enable this kind of behavior?
Here's full demo code – iOS 14 beta 4, iPad in landscape:
Code Block swift import SwiftUI @main struct SidebarSelectionApp: App { var body: some Scene { WindowGroup { ContentView() } } } enum NavigationItem: Int, Identifiable { var id: Int { return self.rawValue } case view1 case view2 case view3 } struct ContentView: View { @State var selection: NavigationItem? = .view1 var body: some View { Sidebar(selection: $selection) } } struct Sidebar: View { @Binding var selection: NavigationItem? var body: some View { NavigationView { list EmptyView() } } var list: some View { List(selection: $selection) { NavigationLink( destination: View1(), tag: NavigationItem.view1, selection: $selection, label: { Text("View 1") }) NavigationLink( destination: View2(), tag: NavigationItem.view2, selection: $selection, label: { Text("View 2") }) NavigationLink( destination: View3(), tag: NavigationItem.view3, selection: $selection, label: { Text("View 3") }) } .listStyle(SidebarListStyle()) .navigationTitle("List") } } struct View1: View { var body: some View { Text("This is View 1").font(.title).foregroundColor(.green) } } struct View2: View { var body: some View { Text("This is View 2").font(.title).foregroundColor(.blue) } } struct View3: View { var body: some View { Text("This is View 3").font(.title).foregroundColor(.red) } }