NSManagedObjectContext's propagatesDeletesAtEndOfEvent set to false causes error on save

荒凉一梦 提交于 2020-01-14 14:13:50

问题


I have a pair of Core Data Entities of One-to-Many relationship.

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

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

Item is a tree node-like entity, which also has a relationship to itself. The tree can grow quite large (more than 10 thousands nodes in a root branch).

There are a parent background NSManagedObjectContext and a main-queue one as the child.

In the hope of making deletion of Items feel faster, I set the main-queue MOC's propagatesDeletesAtEndOfEvent to false. (The change will be saved when the app Resigns Active. ) Unfortunately there will be error messages when the main-queue MOC is saved:

validation recovery attempt FAILED with Error Domain=NSCocoaErrorDomain Code=1600 ...

If propagatesDeletesAtEndOfEvent is the default true, there's no error.

My deletion 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 few talks about the usage of propagatesDeletesAtEndOfEvent. Any examples or explainations of the error will be appreciated.

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

Another question about deleting large number of objects.

来源:https://stackoverflow.com/questions/42675933/nsmanagedobjectcontexts-propagatesdeletesatendofevent-set-to-false-causes-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!