Hi,
Using purely swift programatically (no storyboard), I'm able to create an NSWindow like so:
var window = NSWindow (contentRect: pInstruction.GetFrame (),
styleMask: [.miniaturizable, .closable, .resizable, .titled],
backing: .buffered,
defer: false)
window.title = "Some Title"
window.contentViewController = MyViewController ()
let windowidentifier = NSUserInterfaceItemIdentifier ("WinID1")
window.identifier = windowidentifier
window.makeKeyAndOrderFront(nil)
This works fine and I can see a window on screen. Later, when I want to access the window I can use a utility method:
static func GetWindow(_ pWindowID: NSUserInterfaceItemIdentifier) -> NSWindow? {
let windows = NSApp.windows
for window in windows {
if window.identifier == pWindowID {
return window
}
}
return nil
}
// Then I can call this function like so:
let windowidentifier = NSUserInterfaceItemIdentifier ("WinID1")
let window = GetWindow (windowidentifier)
This also works fine.
However, if I do window.setIsVisible(false)
or window.orderOut (nil)
to temporarily hide the window, then NSApp.windows
returns an empty array and I'm not able to find the window object and my Utility method "GetWindow ()" doesn't work.
Any suggestions on how I can find hidden windows?