OK, I've made the following changes, and (so far) it seems to be working...
(Can you confirm this is what you were suggesting?)
struct NavView: View {
@Binding var main: Main
@State private var selection: UUID?
var body: some View {
NavigationSplitView {
ListView(main: $main, selection: $selection)
} detail: {
if let selection {
DetailView(detail: $main.details.first(where: { $0.id == selection })!)
} else {
Text("Select a detail item to view")
}
}
}
}
struct ListView: View {
@Binding var main: Main
@State private var addedDetailCount = 0
@Binding var selection: UUID?
var body: some View {
List($main.details, editActions: .move, selection: $selection) { $detail in
NavigationLink(detail.title, value: detail)
}
.toolbar {
Button(
LocalizedStringKey("Add Detail"), systemImage: "plus"
) {
addedDetailCount += 1
main.details.append(
.init(title: "new Detail \(addedDetailCount)", description: "description"))
}
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI