gpt4 book ai didi

swift - "Cannot call value of non-function type ' HTTPURL 响应? '"(Alamofire 4.0) [Swift 3.0]

转载 作者:搜寻专家 更新时间:2023-10-30 22:18:28 25 4
gpt4 key购买 nike

我收到此错误:

"Cannot call value of non-function type 'HTTPURLResponse?'"

关于部分:

.response { (request, response, data, error)

我想知道是否有人可以帮助我。

Alamofire.download(urlToCall, method: .get) { temporaryURL, response in
if FileManager.default.fileExists(atPath: finalPath!.path!) {
do {
try FileManager.default.removeItem(atPath: finalPath!.path!)
} catch {
// Error - handle if required
}
}
return finalPath!

}
.response { (request, response, data, error) in

if error != nil {

}
var myDict: NSDictionary?
let path = finalPath!
myDict = NSDictionary(contentsOf: path)

if let dict = myDict {
success(dict)
}

if finalPath != nil {
//doSomethingWithTheFile(finalPath!, fileName: fileName!)
}
}

最佳答案

在 Alamofire 4 中,.response 方法接受一个带有单个参数的闭包,DefaultDownloadResponse

顺便说一下,如果您要使用自己的下载路径,我对您的return finalPath!感到困惑,因为 Alamofire 4 希望您返回一个由文件组成的元组URL 和选项,其中一个选项是.removePreviousFile,这样您就不用手动删除它了。

例如:

Alamofire.download(urlToCall, method: .get) { temporaryURL, response in
let finalURL: URL = ...

return (destinationURL: finalURL, options: .removePreviousFile)
}.response { response in
if let error = response.error {
success(nil)
return
}

if let fileURL = response.destinationURL, let dictionary = NSDictionary(contentsOf: fileURL) {
success(dictionary)
} else {
success(nil)
}
}

关于swift - "Cannot call value of non-function type ' HTTPURL 响应? '"(Alamofire 4.0) [Swift 3.0],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39500976/

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