UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on 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")
        }
    }

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 Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.