Hi guys,
I am getting stuck with the NavigationSplitView.
I am going to have more than 60 individual Views, I can’t just pass in some variables in the “Detail Section”. Because the documents are individually made at the end I want them to be linked to each individual view. How can I tell swift in the “detail section” with a Navigation link how to get to "Document1() View or Document2() View ?
Thank you for any hints…
import SwiftUI
enum Chapter: String, Hashable, CaseIterable {
case chapter1 = "Chapter 1" case chapter2 = "Chapter 2" case chapter3 = "Chapter 3" case chapter4 = "Chapter 4"
}
struct Document: Hashable {
let name: String let chapter: Chapter
}
struct MasterView: View {
let documents = [Document(name: "Document1", chapter: .chapter1), Document(name: "Document2", chapter: .chapter1), Document(name: "Document3", chapter: .chapter2), Document(name: "Document4", chapter: .chapter3), Document(name: "Document5", chapter: .chapter4)] @State private var selectedChapter: Chapter? @State private var selectedDocument: Document? var body: some View { NavigationSplitView { List(Chapter.allCases, id: \.self, selection: $selectedChapter) { chapter in NavigationLink(chapter.rawValue, value: chapter) } } content: { let filteredDocument = documents.filter { $0.chapter == selectedChapter } List(filteredDocument, id: \.name, selection: $selectedDocument) { document in NavigationLink(document.name, value: document) } } detail: { NavigationLink(selectedDocument.name: "Document1", value: Document1()) //error NavigationLink(selectedDocument.name: "Document2", value: Document2()) // error here I want to pass in individual links to each View } }
}
struct MasterView_Previews: PreviewProvider {
static var previews: some View {
MasterView()
.previewInterfaceOrientation(.landscapeLeft)
}
}