I have the code below, which presents a save panel in my SwiftUI macOS App.
It needs to be able to display a file format picker, which is available in the standard accessory view.
However, the key to enable this view seems to be missing (Value of type 'NSSavePanel' has no member 'shouldRunSavePanelWithAccessoryView'), and I can't find any reference on when this was removed, or on an alternative.
Any smart people who know what's going on?
Code:
private func saveToFile() {
appState.triggerViewUpdate.toggle()
let panel = NSSavePanel()
panel.nameFieldLabel = "Save adjusted image as:"
panel.nameFieldStringValue = "adjustedimage.png"
panel.canCreateDirectories = true
panel.showsTagField = false
panel.isExtensionHidden = false
// this generates error "Value of type 'NSSavePanel' has no member 'shouldRunSavePanelWithAccessoryView'"
panel.shouldRunSavePanelWithAccessoryView = true
//
if #available(OSX 11.0, *) {
let allowedContentTypes = [UTType.png, UTType.jpeg]
panel.allowedContentTypes = allowedContentTypes
} else {
let allowedFileTypes = [".png", ".jpeg"]
panel.allowedFileTypes = allowedFileTypes // not sure if we need this
}
panel.begin { response in
if response == NSApplication.ModalResponse.OK, let savePath = panel.url {
if debug { print("savePath: \(savePath)") }
let ciImage = applyFilters(textureIn: appState.imageTexture!)
let cgImage = ciImage.asCGImage()
let nsImage = NSImage(cgImage: cgImage!, size: ciImage.extent.size)
if nsImage.pngWrite(to: savePath) {
print("File saved")
}
}
}
}