I'm trying to download a file using Alamofire, with progress. But I get this error at the progress
line.
Cannot call value of non-function type 'NSProgress'
What's the problem? All the examples I've seen, namely the official one, do the exact same thing!
Alamofire.download(.GET, nsurl!.absoluteString, destination: { (temporaryURL, response) in
return filepath
})
.progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) in // <------ ERROR HERE
dispatch_async(dispatch_get_main_queue(), {
self.progressBar?.progress = totalBytesRead / totalBytesExpectedToRead
})
}
.response { (request, response, _, error) in
self.loadImageFromFile(filepath.absoluteString)
}
EDIT:
After @mvoelkl's suggestion, I added parenthesis to the progress function. But the result stayed the same:
I hope this issue fix when update your Alamofire pod
.
Here mention this issue :- https://github.com/SwiftyJSON/Alamofire-SwiftyJSON/issues/40
This worked for me.
Alamofire.download(.GET, nsurl!.absoluteString, destination: { (temporaryURL, response) in
return file path
})
.progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
let status = Float(totalBytesRead/totalBytesExpectedToRead)
dispatch_async(dispatch_get_main_queue(), {
self.progressBar?.progress = status
})
}
.response { (request, response, _, error) in
self.loadImageFromFile(filepath.absoluteString)
}
What may not work in the above is totalBytesExpectedToRead. It sometimes returns -1, so you may need plug the size of the file you are downloading without resorting to Alamofire.
For me the solution was to add Float around progress.fractionCompleted, so use it like this:
.uploadProgress{ progress in
self.updateProgressBar(imagesToDo: images.count, prog: Float(progress.fractionCompleted))
}
thanks to: https://github.com/Alamofire/Alamofire/issues/1652#issuecomment-259020449
Had the same issue, fixed by using the following code:
Alamofire.upload(.PUT, url, file: file)
.progress({ (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
print("test")
})
Mind the added parentheses for .progress(), found it by generating the code stub with Xcode. Seems there's a mistake in the documentation, if you can confirm this we should file an issue on GitHub ;)
This issue plagued me too. It was caused by an ambiguous issue with NSURLRequest.progress and Alamofire.Request.progress.
To fix the issue I modified Alamofire's source.
Open Alamofire/Request.swift (v3.4.x)
On line 141, rename the function to something that is not progress, I chose requestProgress.
From:
public func progress(closure: ((Int64, Int64, Int64) -> Void)? = nil) -> Self {
To:
public func requestProgress(closure: ((Int64, Int64, Int64) -> Void)? = nil) -> Self {
Proceed to use the function as before with no compiler issues.
来源:https://stackoverflow.com/questions/38326889/ios-cannot-call-value-of-non-function-type-nsprogress