类型' URL'的值没有会员' URLByAppendingPathComponent'

时间:2017-01-06 10:13:56

标签: ios swift cordova

我正在开发一个cordova应用程序并试图将它生成的swift代码转换为swift 3语法,因为当我尝试构建它时会产生错误。我有这个功能

init(configuration: WebAppConfiguration, versionsDirectoryURL: URL, initialAssetBundle: AssetBundle) {
  self.configuration = configuration
  self.versionsDirectoryURL = versionsDirectoryURL
  self.initialAssetBundle = initialAssetBundle

  downloadDirectoryURL = versionsDirectoryURL.appendingPathComponent("Downloading")

  queue = DispatchQueue(label: "com.meteor.webapp.AssetBundleManager", attributes: [])

  downloadedAssetBundlesByVersion = [String: AssetBundle]()
  loadDownloadedAssetBundles()

  let operationQueue = OperationQueue()
  operationQueue.maxConcurrentOperationCount = 1
  operationQueue.underlyingQueue = queue

  // We use a separate to download the manifest, so we can use caching
  // (which we disable for the session we use to download the other files 
  // in AssetBundleDownloader)
  session = URLSession(configuration: URLSessionConfiguration.default, delegate: nil, delegateQueue: operationQueue)
}

第6行

downloadDirectoryURL = versionsDirectoryURL.appendingPathComponent("Downloading")

正在抛出错误

类型'网址'没有会员' URLByAppendingPathComponent'

我不明白是什么导致了这个错误,我已经通过swift 3文档以及其他在线答案查看了,但该行应该是没有错误的,请非常感谢解析此错误的任何见解< / p>

3 个答案:

答案 0 :(得分:2)

有一个&#39; appendingPathComponent&#39;类型&#39; URL&#39;

的方法

请确保您没有为我在为[URL]类型的变量调用方法时犯的错误

let documentURL = FileManager.default.urls(for: .documentDirectory, in: 
.userDomainMask)
        let fileURL = 
documentURL.appendingPathComponent("tempImage.jpg")

通过确保它是URL

类型的变量来修复
let documentURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL = documentURL.appendingPathComponent("tempImage.jpg")

答案 1 :(得分:1)

我认为它appendPathComponent而不是appendingPathComponent,只需重新输入它就会建议您使用正确的语法

答案 2 :(得分:0)

迅速的正确语法4+是:

        let VideoFilePath = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("mergeVideo\(arc4random()%1000)d")?.appendingPathExtension("mp4").absoluteString