我将 @Mundi 答案标记为正确,因为他写了您应该遵循的一般方法。现在,我想在这里分享我是如何调试它的。
首先,我了解到,可以在 xcode 中打开调试并发断言。
您需要在启动时传递以下参数:
-com.apple.CoreData.ConcurrencyDebug 1
现在,在您的应用程序输出中,您应该看到日志消息:
2016-12-12 01:58:31.665 your-app[4267:2180376] CoreData: annotation: Core Data multi-threading assertions enabled.
一旦我打开它,我的应用程序崩溃了synchronizeMyWords
方法(老实说,不仅有。想知道为什么 Apple 在调试模式下默认不包含并发断言?)。我检查了什么defaultExecutor
is in AWS核心库 https://github.com/aws/aws-sdk-ios/blob/master/AWSCore/Bolts/AWSExecutor.m并看到了这个:
+ (instancetype)defaultExecutor {
static AWSExecutor *defaultExecutor = NULL;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
defaultExecutor = [self executorWithBlock:^void(void(^block)()) {
// We prefer to run everything possible immediately, so that there is callstack information
// when debugging. However, we don't want the stack to get too deep, so if the remaining stack space
// is less than 10% of the total space, we dispatch to another GCD queue.
size_t totalStackSize = 0;
size_t remainingStackSize = remaining_stack_size(&totalStackSize);
if (remainingStackSize < (totalStackSize / 10)) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
} else {
@autoreleasepool {
block();
}
}
}];
});
return defaultExecutor;
}
根据他们的if
声明,我的continuationBlock
不保证执行DISPATCH_QUEUE_PRIORITY_DEFAULT
队列。所以,我创建了一个共享dispatch_queue_t
排队并结合调用其上的所有操作performBlockAndWait:
核心数据方法。结果,现在没有崩溃,我提交了新版本。如果我没有收到任何崩溃报告,我将更新这篇文章context
僵尸。