在我的Cocoa应用程序中,一个属性在它不应该被改变时会被修改。为了找出它发生的地方,我提出了有助于缩小问题的断言(我尝试了“观察变量”,但无法理解它的使用方式)。但是现在我面临着一个似乎与它应该相反的主张(请参阅截图)。断言失败应该通过:为什么?
我正在使用自定义运算符(请参见下文)让代码在另一个线程中运行。
我错过了什么,我能做些什么来推进?
import Foundation
infix operator ~>
/**
Executes the lefthand closure on a background thread and,
upon completion, the righthand closure on the main thread.
Passes the background closure's output, if any, to the main closure.
*/
func ~> <R> (
backgroundClosure: @escaping() -> R,
mainClosure: @escaping (_ result: R) ->())
{
queue.async {
let result = backgroundClosure()
DispatchQueue.main.async {
mainClosure(result)
}
}
}
private let queue = DispatchQueue(label: "Edk4ServerRequests")
运营商定制的定义。 (代码改编自https://ijoshsmith.com/2014/07/05/custom-threading-operator-in-swift/)
执行将停止我增加了有关样品中使用的自定义“〜>”运营商的重要信息。 –
我重写了我的代码以确保'isUpdating'不会被另一个线程修改,现在它可以工作。不过,我想了解在提供的截图中,断言失败时,调试器显示“isUpdating”的值为“false”。 –