gpt4 book ai didi

swift - 断言在应该传递 : why? 的地方失败

转载 作者:行者123 更新时间:2023-11-28 16:10:53 24 4
gpt4 key购买 nike

在我的 Cocoa 应用程序中,属性会在不应该更改的时候更改。为了找出它发生的位置,我提出了有助于缩小问题范围的断言(我确实尝试过“观察变量”但无法理解它是如何使用的)。但现在我面临一个似乎与预期相反的断言(见屏幕截图)。

我正在使用自定义运算符(见下文)让代码在另一个线程中运行。

我缺少什么,我可以做些什么来继续前进?

State of Xcode when the program crashes.程序崩溃时 Xcode 的状态。

Stack trace.堆栈跟踪。

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/ )

最佳答案

您可以在属性声明中添加断点。当属性值改变时将停止执行

enter image description here

关于swift - 断言在应该传递 : why? 的地方失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39575362/

24 4 0
文章推荐: php - 我错过了哪种技术来改善该网站的加载时间?不知所措
文章推荐: javascript - 单击/触摸外部 javascript 时关闭菜单
文章推荐: javascript - 使用 JavaScript(不带 jQuery)订购 `