如何遍历 macOS 应用程序窗口直到满足条件?

Posted

技术标签:

【中文标题】如何遍历 macOS 应用程序窗口直到满足条件?【英文标题】:How to iterate over a macOS app’s windows until a condition is met? 【发布时间】: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 告诉我stoplet 常量。

我做错了什么?

【问题讨论】:

【参考方案1】:

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

stop.pointee = true

【讨论】:

谢谢!就是这样。

以上是关于如何遍历 macOS 应用程序窗口直到满足条件?的主要内容,如果未能解决你的问题,请参考以下文章