我正在开发一个 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")
我认为它appendPathComponent
不是appendingPathComponent
,只需重新输入它就会建议你正确的语法
正确的语法 swift 4+ 是:
let VideoFilePath = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("mergeVideo(arc4random()%1000)d")?.appendingPathExtension("mp4").absoluteString