NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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

1      

@WmInk  

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

1      

Hacking with Swift is sponsored by MadMachine

SPONSORED Want to try Swift on microcontrollers? MadMachine provides ways to interact with the physical world in a Swift way. Join us and have fun!

Get it 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.