What's the difference between path and URL in iOS?

别来无恙 提交于 2019-11-30 07:04:18

问题


In a class such as NSFileManager there are 2 versions of practically every method. One for paths and one for URLs. What's the difference? And what's the best practice for converting a URL to a path.


回答1:


URL includes the protocol being used (http:// etc). Path doesn't or doesn't need at least.




回答2:


path is location of a resource (file/directory) in a file system. Just like iOS File System, other environments file system can be Windows file system, Unix etc. Path can have spaces like /docs/random doc/. (between random and doc)

URL is is a reference to a resource anywhere (file system, web HTTP, FTP etc). URL can not have spaces like path.

Web URL: http://stackoverflow.com/
file URL: file://localhost/Users/username/docs/random%20docs/
path for above mentioned file URL: /Users/username/docs/random%20docs/

in layman terms:

URL = protocol (http, file etc) + host (domain name or IP or localhost) + path



来源:https://stackoverflow.com/questions/6546033/whats-the-difference-between-path-and-url-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!