NSSavePanel

I want to include a button that could export some data but I'm stuck:
I want a NSSavePanel open up and when I choose the pass and click save the JSON file will appear but it didn't.
code:

Button {
    let export = exportToJSON(toExported(data.data))
    let openPanel = NSSavePanel()
    openPanel.message = "Choose the exported path:"
    openPanel.begin { response in
        if response == .OK {
            print("\(openPanel.url!)")
            url = openPanel.url!
            let fileManager = FileManager()
            let success = fileManager.createFile(atPath: "\(url)", contents: export)
            debugPrint(success)
        }
    }
} label: {
    Image(systemName: "square.and.arrow.down")
}.padding().buttonStyle(.plain)

console:

file:///Users/***/Documents/Untitled
false

 but I'm stuck

Not very informative.

  • what do you get ?
  • what would you expect ?
NSSavePanel
 
 
Q