挂起NSManagedObjectContext的保存: [英] Hang on NSManagedObjectContext's save:
问题描述
由于某些原因,有时候我的应用程序会挂起以下代码:
For some reason sometimes my app will just hang with the following code:
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Couldn't save: %@", [error localizedDescription]);
}
它并不总是挂起,有时。如果我打破所有的异常,那么Xcode将打破保存调用,但如果我关闭断点,它将永远挂起,没有崩溃或任何东西。
It doesn't always hang, just sometimes. If I break on all exceptions then Xcode will break on the save call, but if I turn off breakpoints it will just hang forever, no crashes or anything.
任何想法?
推荐答案
挂起任何使用 ManagedObjectContext
的东西都是死锁的标志。使用 NSLocking协议或创建每个线程和 MOC >同步它们。
Hanging on anything that uses ManagedObjectContext
is a sign of a deadlock. Either use NSLocking protocol or create a new MOC
for each thread and synchronize them.
来自Apple的另一个有用的文档 - > 与核心数据的并发性
Another useful doc from Apple -> Concurrency with Core Data
这篇关于挂起NSManagedObjectContext的保存:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!