Why I cannot get the right path with NSURL (swift)

266 Views Asked by At

debug info

It is the situation when I use

NSOpenPanel 

and

 NSURL

to get a open file path string coding with Swift. The path should be

"/Users/yy/Downloads/CHS16.FON"

but I got something like

"p\xab\xe2w\xff\x7f"

, and I don't know why.

p.s. Top left hollow circle is a small bug too, actually I have connected the action with a button.

1

There are 1 best solutions below

0
On

NSOpenPanel return a NSURL, fileHandleForReadingAtPath need a String, i've solve this with this function and it works for me :

func nsurlToString (nsurlInit:NSURL) -> String {
    var nsurlProperty:NSURL = nsurlInit
    var urlString:String = nsurlProperty.absoluteString!
    urlString.removeRange(urlString.startIndex..<advance(urlString.startIndex, +7))
    return urlString
 }