如何将NSURL转换为Swift中的String?
下列:
var directoryURL: NSURL var urlString: String = nsurlObject as String
抛出错误:无法将类型“NSURL”的值转换为强制类型“String”
事实证明,您可以访问NSURL的属性(参见
Swift Reference):
原文链接:https://www.f2er.com/swift/320630.htmlvar 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.