【发布时间】:2017-01-28 06:14:01
【问题描述】:
由于迁移到 Swift 3,我发现很难编译使用 Alamofire 的项目。
上传multipartFormData时出现问题:
Alamofire.upload(.POST, URL, headers: headers, multipartFormData: {
multipartFormData in
.
.
.
})
对成员'upload(_:to:method:headers:)'的模糊引用
非常感谢任何帮助,在此先感谢!
已解决:
Alamofire.upload(multipartFormData: { (multipartFormData) in
multipartFormData.append(fileData, withName: "file_pack", fileName: "file_pack", mimeType: "text/plain")
for (key, value) in self.parameters {
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}, with: URL2, encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON { response in
self.delegate?.showSuccessAlert()
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// self.showSuccesAlert()
self.removeImage("frame", fileExtension: "txt")
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
case .failure(let encodingError):
self.delegate?.showFailAlert()
print(encodingError)
}
})
这就是在 Swift 3 中应该如何实现上传方法
【问题讨论】:
-
方法签名已更改。评论您现有的,让 Xcode 的自动完成功能指导您编写新的。
-
你也可以去 gitub 上的 alamofire。 github.com/Alamofire/Alamofire
标签: ios swift networking alamofire swift3