[英]How to fix the Alamofire 5 error for success and failure cases in swift?
In my project, I am using Alamofire 5.9.3 and below is the uploading the data into the server.在我的项目中,我使用的是 Alamofire 5.9.3,以下是将数据上传到服务器。
APISessionController.sharedInstance.sessionManager().upload(multipartFormData: { (multipartFormData) in
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to:url)
{ (result) in
switch result {
case .success(let upload, _, _): // Getting Error: '_' can only appear in a pattern or on the left side of an assignment
upload.uploadProgress(closure: { (Progress) in
self.delegate.uploadProgress(Progress.fractionCompleted)
})
upload.responseJSON { response in
if let JSON = response.result.value as? Dictionary<String, AnyObject> {
}
case .failure(_): //Getting Error : '_' can only appear in a pattern or on the left side of an assignment
Previoulsy I was using Alamofire 4.9.1, It was working fine. Previoulsy 我使用的是 Alamofire 4.9.1,它工作正常。 But it's showing error in Alamofire 5?
但它在 Alamofire 5 中显示错误?
Alamofire's multipart upload APIs changed in Alamofire 5. The encoding completion closure is no longer necessary, you can just use the normal Alamofire APIs. Alamofire 的分段上传 API 在 Alamofire 5 中发生了变化。不再需要编码完成闭包,您可以使用普通的 Alamofire API。
APISessionController.sharedInstance.sessionManager().upload(multipartFormData: { (multipartFormData) in
for (key, value) in parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, to:url)
.uploadProgress { }
.response { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.