FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

NSSavePanel Issue in 10.15

Forums > macOS

When I run my application and use .runModal() on an instance of NSSavePanel I get the following warning.

"WARNING: <NSSavePanel: 0x10065b750> found it necessary to prepare implicitly; please prepare panels using NSSavePanel rather than NSApplication or NSWindow."

I'm assuming this has something to do with Sandboxing and PowerBox, but I've not been able to figure out the correct way they'd like me to call it.

if anyone has any insight it'd be greatly appreciated.

Here is the suspect code.

    @IBAction func saveDocument(_ sender: Any) {
        // Save Commands here.

        let savePanel = NSSavePanel()
        savePanel.title = "Save Example..."
        savePanel.prompt = "Save to file"
        savePanel.nameFieldLabel = "Pick a name"
        savePanel.nameFieldStringValue = "example.png"
//        savePanel.isExtensionHidden = false
        savePanel.canSelectHiddenExtension = true
        savePanel.allowedFileTypes = ["png"]

        let result = savePanel.runModal()

        switch result {
        case .OK:
            guard let saveURL = savePanel.url else { return }
            if let image = exampleOutputImageView.image {
                image.writePNG(to: saveURL)
            } else {
                let alert = NSAlert()
                alert.messageText = "Error"
                alert.informativeText = "Failed to save image."
                alert.alertStyle = .informational
                alert.addButton(withTitle: "OK")
                alert.runModal()
            }
        case .cancel:
            print("User Cancelled")
        default:
            print("Panel shouldn't be anything other than OK or Cancel")
        }
    }

   

@WmInk  

I am having the same problem when ever I have to replace a file.
Would love some insite myself.

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Get started

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.