Home > Mobile >  SwiftUI: deleting Managed Object from cell view crashes app [non-optional property]?
SwiftUI: deleting Managed Object from cell view crashes app [non-optional property]?

Time:07-30

I posted this question:

enter image description here

CodePudding user response:

The explicit handling is needed in anyway, because of specifics of CoreData engine. After object delete it can still be in memory (due to kept references), but it becomes in Fault state, that's why code autogeneration always set NSManagedObject properties to optional (even if they are not optional in model).

Here is a fix for this specific case. Tested with Xcode 13.4 / iOS 15.5

if !item.isFault {
    Text(item.timestamp, formatter: itemFormatter) // << NO CRASH
}
  • Related