In a Swift navigation split view once all of the data has been loaded from core data (indicated by the isLoading variable being equal to false) the Progress View stops being displayed but the detail view is now empty. What I would like have happen at this point is for the Summary view to be displayed. I think this would require programmatically setting the list selection to "Home". How do I need to modify my code to accomplish this? Below is the code.
struct ContentView: View {
@State private var selection: String?
@ObservedObject private var vooVM: VOOViewModel
@ObservedObject private var vfiaxVM: VFIAXViewModel
@ObservedObject private var prinVM: PrincipalViewModel
init(vooVM: VOOViewModel, vfiaxVM: VFIAXViewModel, prinVM: PrincipalViewModel) {
self.vooVM = vooVM
self.vfiaxVM = vfiaxVM
self.prinVM = prinVM
}
let myList = ["Home", "VOO Chart", "VOO List", "VFIAX Chart", "VFIAX List", "Principal Chart", "Principal List"]
var body: some View {
NavigationSplitView {
List(myList, id: \.self, selection: $selection) { listItem in
NavigationLink(value: listItem) {
Text(listItem)
} // end navigation link
} // end list
.navigationSplitViewColumnWidth(250)
} detail: {
if vooVM.isloading == true || vfiaxVM.isloading == true || prinVM.isloading == true {
Spacer()
ProgressView()
.navigationSplitViewColumnWidth(950)
Spacer()
} else if selection == "Home" {
Summary(vooVM: vooVM, vfiaxVM: vfiaxVM, prinVM: prinVM)
.navigationSplitViewColumnWidth(950)
} else if selection == "VOO Chart" {
LineChart(passedInArray: vooVM.values1)
.navigationSplitViewColumnWidth(950)
} else {
Text("Select an option in the list")
}
Spacer()
}
.frame(width: 1200,height: 900, alignment: .center)
} // end body
} // end struct