【问题标题】:How to iterate over a macOS app’s windows until a condition is met?如何遍历 macOS 应用程序窗口直到满足条件?
【发布时间】:2018-03-31 17:18:54
【问题描述】:

要遍历我的 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&lt;ObjCBool&gt; 设置为true:Xcode 告诉我stop 是let 常量。

我做错了什么?

【问题讨论】:

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


    【解决方案1】:

    stop是一个指针,你要设置pointee

    stop.pointee = true
    

    【讨论】:

    • 谢谢!就是这样。
    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 2019-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多