objective-c – 将NSURL转换为本地文件路径

我有一个NSURL看起来像这样:

file://localhost/Users/myuser/myfile.txt

是否有一个标准函数将其转换为本地文件路径,如下所示:

/Users/myuser/myfile.txt
使用 – [NSURL path]方法:

NSLog(@"%@", myUrl.path);

从文档:

The path of the URL, unescaped with the stringByReplacingPercentEscapesUsingEncoding: method. If the receiver does not conform to RFC 1808, returns nil.

If this URL object contains a file URL (as determined with isFileURL), the return value of this method is suitable for input into methods of NSFileManager or NSPathUtilities. If the path has a trailing slash it is stripped.

Per RFC 3986, the leading slash after the authority (host name and port) portion is treated as part of the path.

请注意,您可以使用[NSURL fileURLWithPath:]创建此类URL。

http://stackoverflow.com/questions/6956325/convert-nsurl-to-local-file-path

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:objective-c – 将NSURL转换为本地文件路径