开发者

Reasons for NSManagedObjectMergeError error on [NSManagedObjectContext save:]

I have a application that combines开发者_StackOverflow中文版 threading and CoreData.

I am using one global NSPersistentStoreCoordinator and a main NSManagedObjectContextModel.

I have a process where I have to download 9 files simultaneously, so I created an object to handle the download (each individual download has its own object) and save it to the persistentStoreCoordinator.

In the [NSURLConnection connectionDidFinishLoading:] method, I created a new NSManagedObject and attempt to save the data (which will also merge it with the main managedObjectContext).

I think that it is failing due to multiple process trying to save to the persistentStoreCoordinator at the same time as the downloads are finishing around the same time.

What is the easiest way to eliminate this error and still download the files independently?


The NSManagedObjectContext instances know how to lock the NSPersistentStoreCoordinator. Since you are already using one NSManagedObjectContext per thread that is most likely not the issue.

It would help to know what the error is that you are getting. Unroll the NSError and look at its -userInfo. If the userInfo dictionary contains the key NSDetailedErrors. The value associated with this key will be an array that you can loop over and look at all the errors inside. That will help to determine what is going on.

It is quite possible that the error can be something as simple as validation or a missing required value and has nothing to do with the actual threading.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜