The code below works, in that it successfully creates an item and attached it to the parent item, but the parent view doesn't show the new child until you navigate away from the parent and then back to it.
Parent:
Child1
Child2
// Add Child 3 and this does not refresh when returning through the dismiss() call, but if I navigate to the grand Parent, and then back to the Parent, Child 3 is there. Any ideas?
NavigationStack {
Form {
LabeledContent {
TextField("Item", text: $name)
} label: {
Text("Item:")
}
}
.navigationTitle("Add New Item")
.toolbar {
Button("Save") {
var tmp = Item(timestamp: Date(), name: name, parent: itemParent)
if(itemParent != nil) {
itemParent!.children.append(tmp)
}
context.insert(tmp)
try? context.save()
dismiss()
}
}
}