Post

Replies

Boosts

Views

Activity

Reply to SwiftUI update of deleted CoreData entities from different Tab
hi Bernhard, you could take a look at my ShoppingList14 project over on GitHub - https://www.github.com/delawaremathguy/ShoppingList14, where i (sort of) solve the problem of having two edit views open on the same CD object in two different tabs and "delete" the object in one of those views. i make sure that the second one goes away before it can be seen when returning to the other tab. you will find my comments about this situation in the file AddOrModifyItemView.swift. i can't say i know enough about using isFault, since it will be true when the object is deleted, but isDeleted will be false. on the other item you mentioned, about changing a property of a CD object Y that's associated via some relationship with a CD object X, no change has been made to the attributes of X (only to the underlying NSSet or NSOrderedSet for the relationship of X). so X never sees a change to one of the properties in Y. you can work around this; when a change is made to Y, find any and all X to which it is related and call X.objectWillChange.send(). you will find that i do this in ShoppingList14, and i have included some lengthy comments about this strategy, mostly for the case where X has computed properties that are based on the associated Ys (see Item+Extensions.swift and Location+Extensions.swift). hope that helps, DMG
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to SwiftUI update of deleted CoreData entities from different Tab
hi, your question made me realize i had something like this situation occurring as a very remote possibility in one of my projects. my solution (which works, as far as i have tested) is: when a detail view is initialized, record the id of the object you display (you do have an id: UUID? attribute on the object, yes?). with every .onAppear() of the DetailView, use a Core Data fetch to see whether you still have a CD object with that id. if no such object exists, then just dismiss the detail view right away. hope that helps, DMG
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21