I'm trying to show the file picker window from my macOS GUI app written with SwiftUI. So I call this:
let panel = NSOpenPanel()
//panel.allowedFileTypes = ["myext"] //I get a warning here that it's deprecated
//Trying to use the following instead:
let fileType = UTType(tag: "myext", tagClass: .filenameExtension, conformingTo: nil)
if(fileType != nil)
{
panel.allowedContentTypes = [fileType!]
}
else
{
assert(false)
}
panel.allowsMultipleSelection = false
panel.canChooseDirectories = false
panel.canChooseFiles = true
let resp = panel.runModal()
The panel is shown, but I can't select any file, including the ones with my .myext
extension.
But if I uncomment panel.allowedFileTypes
line, everything works as I expected.
So what am I doing wrong with that allowedContentTypes
?
PS. Or, at least how do I mute that deprecated warning in Swift? (The allowedFileTypes
works fine, what's the point of deprecating it!)
conformingTo: .data
instead of thenil
- I don't think it's in the documentation? – Averi