如何修复 swift 中成功和失败案例的 Alamofire 5 错误?
How to fix the Alamofire 5 error for success and failure cases in swift?
在我的项目中,我使用的是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
之前我使用的是 Alamofire 4.9.1,它运行良好。但是它在 Alamofire 5 中显示错误?
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 { }
在我的项目中,我使用的是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
之前我使用的是 Alamofire 4.9.1,它运行良好。但是它在 Alamofire 5 中显示错误?
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 { }