iOS - Cannot call value of non-function type 'NSProgress'

戏子无情 提交于 2019-12-05 14:08:03

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.

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