开发者

NSMergeConflict with multiple threads

开发者 https://www.devze.com 2023-04-10 12:32 出处:网络
A 1 <----> * B I\'m using core data in an iOS application.A and B are entities that have a 1-to-many relationship between A and B.I have a background thread that updates and creates B. A is up
A 1 <----> * B

I'm using core data in an iOS application. A and B are entities that have a 1-to-many relationship between A and B. I have a background thread that updates and creates B. A is updated on the main thread, except when I add B to A on the background thread, because of the inverse relationship A gets updated. I have separate MOCs for the main and background thread.

I've added a mergeChangesFromContextDidSaveNotification: on the main thread, but I get a NSMergeConflict on the background thread for A. Looking at the userInfo of the NSMergeConflict doesn't help, because all the attributes are the same, it's the to many relationships that I imagine are conflicting, and those arent returned by nsmergeconflict.

I've tried adding a mergeChangesFromContextDidSaveNotification: to the background thread, but it now deadlocks when both threads try to save.

I've looked over the answer for this NSMergeConflict question. I've tried adding the mergeChangesFromContextDidSaveNotification: notification, but I'm still seeing the NSMergeConflict. I don't think that any of the NSMergePolicy options are applicable,开发者_运维问答 because I want to keep all of the persistent store's changes except for the relationship. I'm also not clear on how I can "manually resolve any conflicts".

How would I be able to resolve or avoid these conflicts?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号