如何迭代 macOS 应用程序的 windows 直到满足条件?
How to iterate over a macOS app’s windows until a condition is met?
为了遍历我的 macOS 应用程序中的所有 windows,我使用 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
为了遍历我的 macOS 应用程序中的所有 windows,我使用 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