Getting thread errors when calling obtainPermanentIDsForObjects

独自空忆成欢 提交于 2020-01-15 10:43:31

问题


I'm creating a new NSManagedObject and inserting it into a context with concurrency type private queue (so it runs on a background thread).

Right before I save, I call this:

[appDelegate.backgroundMOC obtainPermanentIDsForObjects:
       [NSArray arrayWithObject:newObject] error:&error];

Then I save:

[appDelegate.backgroundMOC save:&err];

However, I get a EXC_BAD_ACCESS crash. Looking at the stacktrace, I see:

0 semaphore_wait_trap
7-[NSManagedObjectContentSave:]

I'm guessing the problematic line is the semaphore_wait_trap, but I'm not sure how that's caused.

If I comment out the line obtainPermanentIDsForObjects, the problem goes away.

Any ideas?


回答1:


Due to a bug in obtaining object ids (http://openradar.appspot.com/11478919), you need to pass in all newly created objects to -[NSManagedObjectContext obtainPermanentIDsForObjects:error:].



来源:https://stackoverflow.com/questions/11315479/getting-thread-errors-when-calling-obtainpermanentidsforobjects

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