【发布时间】:2016-12-09 02:44:02
【问题描述】:
启用 Zombies 后,我在以下 saveToURL 调用中收到标题错误(发送到已释放的 NSError 实例的消息):
[aDocument saveToURL:aDocument.fileURL
forSaveOperation:UIDocumentSaveForOverwriting
completionHandler:^(BOOL success) { ...
堆栈跟踪如下所示:
aDocument 是 UIManagedDocument 的子类的一个实例。我进行了并发调试,我查看了是否有任何线程冲突,但还没有找到。我该如何调试?
编辑:还尝试了以下代码,但发生了相同的崩溃
__weak typeof(self) weakSelf = self;
[aDocument saveToURL:aDocument.fileURL forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success) {
if (success) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf documentSaved:aDocument forRestoredAssessment:patientAssessment];
});
}
}];
编辑:添加赏金
【问题讨论】:
-
你在completionHandler里面做什么?
-
这个方法被称为... [self documentSaved:aDocument forRestoredAssessment:patientAssessment];它做了很多事情。
-
一般来说,从不是主队列的任何线程中触摸 UIKit 中的任何内容或与 UIKit 直接相关的任何内容都是不安全的。事实上,我认为这是问题的核心。
-
aDocument是局部变量还是属性? -
@BradThomas 我在 UIDocument 文档中注意到这一行:
Instead, in this case, the error is available to your app in the handleError:userInteractionPermitted: method and in the UIDocumentStateChangedNotification notification.这里:developer.apple.com/reference/uikit/uidocument/…。也许如果您收听此通知,您可能会弄清楚 NSError 发生了什么。
标签: objective-c memory-management nserror nszombie uimanageddocument