我试图开始Operation在侧面项目中使用s而不是在我的网络代码中散布基于闭包的回调以帮助消除嵌套调用.所以我正在做一些关于这个主题的阅读,我遇到了这个实现:
open class AsynchronousOperation: Operation {
// MARK: - Properties
private let stateQueue = DispatchQueue(label: "asynchronous.operation.state", attributes: .concurrent)
private var rawState = OperationState.ready
private dynamic var state: OperationState {
get {
return stateQueue.sync(execute: {
rawState
})
}
set {
willChangeValue(forKey: "state")
stateQueue.sync(flags: .barrier, execute: {
rawState = newValue
})
didChangeValue(forKey: "state")
}
}
public final override var isReady: Bool {
return state == .ready && super.isReady
}
public final override var isExecuting: Bool {
return state …Run Code Online (Sandbox Code Playgroud) 有时在使用我的基于文档的 mac 应用程序(Xcode 10、Swift 4.2、macOS 10.13.5)时,我在控制台中收到以下错误:
_NSDocumentBasicAsyncOperation 0x60c000233c40 isFinished=YES 没有被它所在的队列启动
我理解当您使用异步操作时会发生这种情况(参见,例如,this question),但我不知道。这是 Cocoa 自己完成的事情,所以我的问题是我应该有多担心,我怎样才能找出这个错误的来源?我覆盖了 NSDocumentController 和 NSDocument 中的一些函数;我怀疑它是 NSDocument 中的东西(我在每个打开的文档中都会得到其中一个),但是我很困惑从哪里开始进行故障排除,并且对可能发生的事情感到好奇。