在我的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」。 –