Deleting core data entity from inside a withAnimation block causes concurrency violation

withAnimation(.easeInOut){
    delete(deck)
}

func delete(deck){
   container.viewContext.delete(deck)
   do{
      try container.viewContext.save()
   } catch let error {
     print("Delete Failed
   }
}

This (pseudo) code almost always throws a CoreData concurrency violation when running on device from Xcode. It doesn't seem to happen when running the app directly on device (without Xcode)

Wrapping the delete with a viewContext.perform block stops the crash but the delete no longer animates in the VGrid

Appreciate any help

Here are the error message: CoreData`+[NSManagedObjectContext Multithreading_Violation_AllThatIsLeftToUsIsHonor]:     0x1cddb5424 <+0>:  pacibsp      0x1cddb5428 <+4>:  stp    x29, x30, [sp, #-0x10]!     0x1cddb542c <+8>:  mov    x29, sp     0x1cddb5430 <+12>: bl     0x1d2bfcfb0 ->  0x1cddb5434 <+16>: brk    #0x1

com.apple.SwiftUI.AsyncRenderer (15): EXC_BREAKPOINT (code=1, subcode=0x1cddb5434)

First, ask yourself, how many times is the animation block called, then ask yourself if core data is a concurrent framework. Coredata calls like this should be in response to a one-off button click or action and a test to determine if the entity being deleted also exists before hand.

The code IS called when the user clicks on a delete button. Id like to animate the deletion .. how else can that be done if we done wrap it in an animation block?

Deleting core data entity from inside a withAnimation block causes concurrency violation
 
 
Q