Hi,
I've exactly same behavior and found a pretty good solution :
I assume you have something like this in your tasks view list :
ForEach (selectedProject.tasks) { task in
// Your UI here
}
My solution is to not use selectedProject.tasks on this view but use @FetchRequest to get tasks for selected project. Code is something like :
@ObservedObjectvar selectedProject: Project
@FetchRequest var tasks: FetchedResultsTask
init(withProject project: Project) {
self.selectedProject = project
_tasks = FetchRequest(
entity: Task.entity(),
sortDescriptors: [
NSSortDescriptor(keyPath: \Task.text, ascending: true)
],
predicate: NSPredicate(format: "project == %@", project)
)
}
And change your ForEach by (and any where you were using selectedProject.tasks) :
ForEach (tasks) { Task in
// Your UI here
}
With this solution : Listing works using ForEach
Deleting a Task works also.
When you edit a Task in DetailsView, go back to this list view, it updates list content (it should already work)
But most important : When you edit a Task in DetailsView, go back to list view and go again in DetailsView, it is updated like expected!
I hope it helps you. Best,
Jonathan
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: