Why does fileURLWithPath: give me a file://localhost/ URL?

Posted by jxpx777 on Stack Overflow See other posts from Stack Overflow or by jxpx777
Published on 2010-04-19T20:18:03Z Indexed on 2010/04/19 20:23 UTC
Read the original article Hit count: 828

Filed under:
|

I have a project I'm working on and this seems like the simplest thing in the world, but the +[NSURL fileURLWithPath:] factory method is returning a strange URL. I created an empty sample project to isolate the problem and in my app delegate's applicationDidFinishLaunching: method I have this simple code:

NSString *path = [@"~/Documents" stringByExpandingTildeInPath];
NSURL *url = [NSURL fileURLWithPath:path];
NSLog(@"%@ | %@", path, url);

and the NSLog result looks like this:

/Users/myusername/Documents | file://localhost/Users/myusername/Documents/

when I would expect the URL to be file:///Users/myusername/Documents.

Any thoughts on why this is behaving like this? (10.6.3 in case it matters.)

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nsurl