0

I'm using the following to let a user pick a file to save in my macOS app:

let panel = NSSavePanel()
let resp = panel.runModal()
if(resp == .OK)
{
    let strFilePath = panel.url?.path();
}

The problem is that NSSavePanel::url::path escapes spaces (and possibly other characters) in a path. So instead of:

/Users/user/Documents/file 2.txt

I'm getting:

/Users/user/Documents/file%202.txt

So how do I get it to return the former path?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • i think you want to get `lastpathcompnent` and play with it. because it will proper file name. – Jatin Apr 17 '23 at 10:24
  • This seems to have fixed it, but I'm not sure why `path()` returns those escaped sequences? `let strFilePath = panel.url?.path().removingPercentEncoding;` – c00000fd Apr 17 '23 at 10:30
  • that sequences represent space as per my understanding. because i face it alot. `space` = `%20` in path. – Jatin Apr 17 '23 at 10:33
  • It represents a space in a URL but not in a POSIX file path. – c00000fd Apr 17 '23 at 10:34

0 Answers0