I am using an NSOpenPanel to select a file and then do some post processing on it. The problem is that NSOpenPanel is not hiding its widow or window frame after the file has been selected and control has been returned to the app. There is a solid white window that replaces the panel once the file has been selected and it does not go away until after the post processing of the file has been done. It appears that the window or frame is not removed until after the main thread has completed its cycle. I have tried this with both runModal() and begin(completionHandler:) with the same results. If I perform the post processing in background, the window closes as expected, but this is not acceptable in this app as the post processing needs to be completed before any other processing is done.
Here is a simple testcase involving both the runModa and begin methods. The sleep() is used to simulate processing.
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
/
}
override var representedObject: Any? {
didSet {
/
}
}
@IBAction func showPanel(_ sender: Any) {
let Panel = NSOpenPanel()
let result = Panel.runModal()
print(result)
print(Panel.url!.path)
sleep(5) /
}
@IBAction func showPanelCompletionHandler(_ sender: Any) {
let panel = NSOpenPanel()
panel.begin(completionHandler: ){ response in
print("in completionHandler")
print(panel.url!.path)
sleep(5) /
}
}
}