Converting URL to String and back again
fileURLWithPath()
is used to convert a plain file path (e.g. "/path/to/file") to an URL. Your urlString
is a full URL string including the scheme, so you should use
let url = NSURL(string: urlstring)
to convert it back to NSURL
. Example:
let urlstring = "file:///Users/Me/Desktop/Doc.txt"let url = NSURL(string: urlstring)println("the url = \(url!)")// the url = file:///Users/Me/Desktop/Doc.txt