I just made this same error, and had trouble with it for quite some time. I was following along with the Apple guide:
The main issue is that the Apple docs show us using the Objective-C method:
[panel beginSheetModalForWindow:window completionHandler:^(NSInteger result){ }
I did an ad hoc translation into Swift, with help from Xcode autocomplete:
let openPanel = NSOpenPanel()
openPanel.beginSheet(window) { (modalResponse: NSApplication.ModalResponse) in
}
This does not work. When the code is run, the Window's title bar disappears + no panel is shown.
Use the correct Swift method instead, beginSheetModal
:
openPanel.beginSheetModal(for: window) { (modalResponse: NSApplication.ModalResponse) in
}