NSManagedObjectContext propagates DeletesAtEndOfEvent set to false, causes error while saving

I have a couple of master data relationships with one-to-many relationships.

Department <-(optional) (delete rule: Cascade) (optional)->> Item Item <-(optional) (delete rule: Nullify) (optional)->> Department 

Item is a tree node-like object, which is also related to itself. A tree can grow quite large (more than 10 thousand nodes in the root branch).

There is a parent background NSManagedObjectContext , and the main one as a child.

In the hope of speeding up the removal of Items I set the main MOC propagatesDeletesAtEndOfEvent queue to false , (The change will be saved if the application cancels the action.) Unfortunately, error messages will appear when saving the MOC of the main queue:

attempt to restore FAILED check with error domain = NSCocoaErrorDomain Code = 1600 ...

If propagatesDeletesAtEndOfEvent is the default value of true , there are no errors.

My removal code looks like this: nothing special:

 department.removeFromItems(items as NSSet) // Optional. Also tried without this line. for i in items { self.managedObjectContext!.delete(i) } 

I see very little talk about using propagatesDeletesAtEndOfEvent . Any examples or explanations of the error will be appreciated.

Here is a related question . But this has nothing to do with the propagatesDeletesAtEndOfEvent property.

Another question is about deleting a large number of objects.

+3
source share

Source: https://habr.com/ru/post/915653/


All Articles