“Cannot call value of non-function type 'HTTPURLResponse?'” (Alamofire 4.0) [Swift 3.0]

*爱你&永不变心* 提交于 2019-12-05 06:09:12

In Alamofire 4, the .response method takes a closure with a single parameter, the DefaultDownloadResponse.

By the way, if you're going to use your own path for the download, I'm confused by your return finalPath! because Alamofire 4 expects you to return a tuple consisting of the file URL and the options, of which one of the options is .removePreviousFile, which saves you from manually removing it yourself.

For example:

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)
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!