如何迭代macOS应用程序的窗口,直到满足条件?

时间:2018-03-31 17:18:54

标签: swift macos swift4 macos-high-sierra xcode9.3

要迭代我的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告诉我stoplet 1}}常数。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

stop是指针,您必须设置pointee

stop.pointee = true