How to convert NSURL to String in Swift

后端 未结 1 1923
一生所求
一生所求 2021-02-03 19:49

How do you convert an NSURL to a String in Swift?

The following:

var directoryURL: NSURL
var urlString: String = nsurlObject as String

相关标签:
1条回答
  • 2021-02-03 19:59

    It turns out there are properties of NSURL you can access (see Swift Reference):

    var directoryURL: NSURL
    var urlString: String = directoryURL.absoluteString
    // OR
    var urlString: String = directoryURL.relativeString
    // OR
    var urlString: String = directoryURL.relativePath
    // OR
    var urlString: String = directoryURL.path
    // etc.
    
    0 讨论(0)
提交回复
热议问题