[ad_1]
I’m working on a test project. My goal is to be able to navigate from HomeList
to SampleDataList
and then to some different view that’s based on the URL file type. I do not want to use Master/Detail.
With the code given below, I get the following error:
Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView. A NavigationLink is presenting a value of type "URL" but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated.
I have tried…
- Moving
navigationDestination(for:destination:)
toHomeList
. This doesn’t work. - Embedding
SampleDataList
in aNavigationStack
. This doesn’t work either. - Using a
NavigationPath
. I’m not sure I did this correctly, but it didn’t work either.
struct HomeList: View {
var body: some View {
NavigationStack {
List {
NavigationLink {
SampleDataList()
} label: {
Text("Sample Data Picker")
}
}
}
}
}
extension URL: Identifiable {
public var id: Int { self.hashValue }
}
struct SampleDataList: View {
var urls: [URL] {
let path = Bundle.main.resourcePath!
let url = URL(fileURLWithPath: path).appendingPathComponent("SampleData")
return try! FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil)
}
var body: some View {
List(urls) { url in
NavigationLink(value: url) {
Text("\(url.lastPathComponent)")
}
}
.listStyle(PlainListStyle())
.navigationDestination(for: URL.self) { url in
Text("\(url.lastPathComponent)")
}
}
}
[ad_2]