Reputation: 2719
As part of testing my MacOS Document-based Swift app, I'm logging a URL with:
NSLog(url.absoluteString)
If that URL has spaces, I get crazy results, like:
file:///Users/Ben/Desktop/Test 0.000000older/Lotti2issa(null)apientiae220Basso ontinuo2ooklet.pdf
Tha actual filepath is:
/Users/Ben/Desktop/Test folder/Lotti Missa Sapientiae - Basso continuo booklet.pdf
Is this just some formatting issue with absoluteString, or is a problem with my URL?
I'm not generating the URL myself: the value is coming in from AppKit, as it's the parameter in a function of NSDocument that I'm overriding.
Upvotes: 0
Views: 169
Reputation: 285069
To get the path of a file system URL use always the path
API.
NSLog(url.path)
absoluteString
returns a percent escaped URL string including the scheme
(file://
, https//
etc.) and the host
which is irrelevant in the file system.
Upvotes: 1