gpt4 book ai didi

ios - 类型 'URL' 的值没有成员 'URLByAppendingPathComponent'

转载 作者:可可西里 更新时间:2023-11-01 00:48:30 26 4
gpt4 key购买 nike

我正在开发一个 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")

抛出一个错误

“URL”类型的值没有成员“URLByAppendingPathComponent”

而且我不明白是什么导致了这个错误,我已经浏览了 swift 3 文档以及在线的其他答案,但是该行应该没有错误,请任何解决这个错误的见解将不胜感激

最佳答案

“URL”类型有一个“appendingPathComponent”方法

确保你没有犯我为类型 [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")

关于ios - 类型 'URL' 的值没有成员 'URLByAppendingPathComponent',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41503411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com