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

I get this error:

"Cannot invoke value of non-function type HTTPURLResponse?"

in section:

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

and I was wondering if anyone could help me with this.

 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!) } } 
+6
source share
1 answer

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

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

For instance:

 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) } } 
0
source

All Articles