Converting URL to String and back again

后端 未结 10 1344
攒了一身酷
攒了一身酷 2020-12-22 20:29

So I have converted an NSURL to a String. So if I println it looks like file:///Users/... etc.

Later I want this

10条回答
  •  半阙折子戏
    2020-12-22 21:31

    In Swift 4 and Swift 3, To convert String to URL:

    URL(string: String)
    

    or,

    URL.init(string: "yourURLString")
    

    And to convert URL to String:

    URL.absoluteString
    

    The one below converts the 'contents' of the url to string

    String(contentsOf: URL)
    

提交回复
热议问题