I'm having trouble converting URL to string. The getScreenShotDirectory() path is file:///Users/Pat/Desktop/
.
My goal is to convert it to String, so the path can look like /Users/Pat/Desktop/
let urlString = getScreenShotDirectory()
let pathURL = URL(string: getScreenShotDirectory())! // error
I would gladly provide more code if needed.
It appears that your getScreenShotDirectory()
method is already a URL
. So you get the error trying to pass a URL
to the URL(string:)
method which, of course, expects a String
, not a URL
.
The simple solution is to properly convert the URL
to a path string:
let pathURL = getScreenShotDirectory() // URL
let pathString = pathURL.path // String
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With