Any examples of IKSaveOptions() / NSSavePanel() filetype selectors out there?

Hi all,

my macOS project needs a way to save images in multiple formats. The code to export a CIImage to these formats is in place and working, but I'm struggling with getting my NSSavePanel() to display the file type selector you see on most apps.

I found out that IKSaveOptions() can be used to add this to an existing NSSavePanel(), but havent found any examples on how to implement this.

Please take a look at my code, and let me know if something rings a bell?

Thanks in advance!

Code Block swift
private func saveToFile() {
        let panel = NSSavePanel()
        let options = IKSaveOptions()
        options.addAccessoryView(to: panel) // seems to get ignored

I then show the panel with this code. The panel is working, but never shows the file selector controls:

Code Block swift
panel.begin { response in
if response == NSApplication.ModalResponse.OK, let savePath = panel.url {
let nsImage = NSImage(cgImage: cgImage!, size: ciImage.extent.size)
if nsImage.pngWrite(to: savePath) {
print("File saved")
}
}
}


Answered by OOPer in 661951022

let me know if something rings a bell?

You are not using the documented initializer of IKSaveOptions.
init(imageProperties:imageUTType:)

Code Block
let panel = NSSavePanel()
let options = IKSaveOptions(imageProperties: [:],
imageUTType: kUTTypeImage as String)!
options.addAccessoryView(to: panel)
panel.begin { response in
if response == .OK, let savePath = panel.url {
//...
}
}


Accepted Answer

let me know if something rings a bell?

You are not using the documented initializer of IKSaveOptions.
init(imageProperties:imageUTType:)

Code Block
let panel = NSSavePanel()
let options = IKSaveOptions(imageProperties: [:],
imageUTType: kUTTypeImage as String)!
options.addAccessoryView(to: panel)
panel.begin { response in
if response == .OK, let savePath = panel.url {
//...
}
}


That worked like a charm, OOPer, thank you!

Any examples of IKSaveOptions() / NSSavePanel() filetype selectors out there?
 
 
Q