TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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")
        }
    }

3      

@WmInk  

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

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.