0

I have an app that lets the user input a file, process it, then lets the user save the file. I ran into a small problem with the save dialog. The file type that my app allows the user to save should only be txt files. But I do allows the user to use other types as well so I put true in allowsOtherFileTypes. Here is my code:

let savePanel = NSSavePanel()
savePanel.allowedFileTypes = ["txt"]
savePanel.allowsOtherFileTypes = true
savePanel.beginSheetModal(for: self.window!, completionHandler: { response in
        // Save handlers here.
    })

The problem is, if the user put another extension other than txt, my app suppose to pop up an alert asking for sure if the user wants to use that extension for the file, but the alert pop up as it's own window instead of a sheet:

Window instead of Sheet

What should I add to make this alert appear as a sheet over the save window instead of on a new window?

System: macOS Sierra, Xcode 8.2, Swift 3

Tom Shen
  • 1,838
  • 3
  • 19
  • 40

1 Answers1

1

Tom,

On macOS you can't have a sheet on top of a sheet. Since macOS is putting the first sheet (the save panel) on top of your window, the second dialog confirming the non standard file extension for your app can't be a sheet.

Hope that helps.

Lucien
  • 61
  • 3