I'm trying to figure out a proper way to list and remove/add items in a Core Data relationship.
Image that a Project entity has a one-to-many relationship to Task (one-to-one inverse).
When listing projects it works smoothly:
Code Block swift ForEach(self.projects) { project in // NavigationLink to a ProjectDetailsView }
So, when it goes to another View to show the selected project details, then the Core Data relationship get very weird.
What's the correct way to do a ForEach on selectedProject.tasks since it's an old NSSet? not compatible with any SwiftUI component?
How to add/remove items on this relationship?
Code Block swift selectedProject.addToTasks(newlyCreateTask) try? self.managedObjectContext.save()
It saves the Core Data entities, but do not update automatically the wrapped Array of tasks, what do not happens for project list because ForEach is watching the Core Data entities directly.
I didn't find any WWDC video with this kind of example, on YouTube is full of solutions to list only, doing the Array wrapping but none for add/remove items.
Cheers.