要在macOS应用程序中的所有窗口上迭代,我使用enumerateWindows(options:using:)如下:

NSApplication.shared.enumerateWindows(options: .orderedFrontToBack, using: {
    (window: NSWindow, stop: UnsafeMutablePointer<ObjCBool>) in
    if let vc = window.contentViewController as? SomeCustomViewController {
        if someCondition {
            stop = true // “Cannot assign to value: 'stop' is a 'let' constant”
        }
    }
})

我想在满足someCondition时停止枚举,但无法将UnsafeMutablePointer<ObjCBool>设置为true:Xcode告诉我stop是一个let常量。
我做错什么了?

最佳答案

stop是指针,必须设置pointee

stop.pointee = true

关于swift - 如何遍历macOS应用程序的窗口直到满足条件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49590424/

10-13 06:00