简体   繁体   English

无法将类型'(_,_,_)->()'的值转换为预期的参数类型'Int64'

[英]Cannot convert value of type '(_, _, _) -> ()' to expected argument type 'Int64'

upload(urlRequest.1, with: urlRequest.0)
        Progress {(bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in // Error Comes Here
                print("\(Int64(totalBytesWritten)) / \(Int64(totalBytesExpectedToWrite))")
            }
            .responseJSON
            {
                response in

                hideLoading()

                showToast("Profile Updated Successfully!!")
            }

The problem is that you've replaced .uploadProgress with Progress , but have not changed the three parameters to the closure to be the single Progress parameter. 问题是您已经用Progress替换了.uploadProgress ,但是没有将闭包的三个参数更改为单个Progress参数。

When you call .uploadProgress , the first parameter to that closure is a Progress (formerly known as NSProgress ). 调用.uploadProgress ,该关闭的第一个参数是Progress (以前称为NSProgress )。 But the Alamofire method name, uploadProgress , is unchanged. 但是Alamofire方法的名称uploadProgress保持不变。 Only the parameters to the closure have changed. 仅闭包的参数已更改。

Thus you want something like: 因此,您需要类似:

Alamofire.upload(data, with: request)
    .uploadProgress { progress in
        print(progress.fractionCompleted)
    }
    .responseJSON { response in
        self.hideLoading()

        switch response.result {
        case .failure(let error):
            self.showToast("Problem uploading: \(error.localizedDescription)")
        case .success:
            self.showToast("Profile Updated Successfully!!")
        }
}

Bottom line, the upload progress method is called uploadProgress , and it takes one parameter, a NSProgress / Progress object. 最重要的是,上载进度方法称为uploadProgress ,它采用一个参数,即NSProgress / Progress对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法转换“字符串”类型的值? 到预期的参数类型 &#39;Int64&#39; swift ios - Cannot convert value of type 'String?' to expected argument type 'Int64' swift ios 无法使用类型为(Int64,String)的参数列表调用setValue - Cannot invoke setValue with an argument list of type (Int64, String) 无法将Int类型的值转换为预期的参数类型Bool - Cannot convert value of type Int to expected argument type Bool &#39;无法将&#39;Int&#39;类型的值转换为预期的参数类型&#39;CGPoint&#39; - 'Cannot convert value of type 'Int' to expected argument type 'CGPoint' 无法在Swift 3中将字符串类型的值转换为预期的参数类型int - cannot convert value of type string to expected argument type int in swift 3 无法将 Int 类型的值转换为预期的参数类型“...” - Cannot convert value of type Int to expected Argument type '...' 无法转换类型为“任何对象!”的值 到预期的参数类型“ Int” - cannot convert value of type 'Anyobject!' to expected argument type 'Int' 无法将类型“ Int”的值转换为预期的参数类型“ String”? - Cannot convert value of type 'Int' to expected argument type 'String'? 无法将时间&#39;Int&#39;的值转换为Swift 2中的预期参数类型&#39;NSPropertyListReadOptions&#39; - Cannot convert value of time 'Int' to expected argument type 'NSPropertyListReadOptions' in Swift 2 无法将类型“ Int”的值转换为预期的参数类型“ UnsafeMutablePointer <Int32> ! - Cannot convert value of type 'Int' to expected argument type 'UnsafeMutablePointer<Int32>!'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM