无法调用非函数类型的值 '((UInt) -> Data?)!'与 Alamofire 4
Cannot call value of non-function type '((UInt) -> Data?)!' with Alamofire 4
我正在尝试为 Swift 3 和 Alamofire 4 转换代码,但我目前遇到以下错误:
Cannot call value of non-function type '((UInt) -> Data?)!'
在这一行:
multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)
请您对本案提出意见。我当前的代码如下。
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(imageData!, withName: "image", fileName: nowString + "To" + receiverString! + ".jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)
}
},to:"uploadimgURL"
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _)
upload.responseString(completionHandler: { (response) in
debugPrint(response)
})
case .failure(let encodingError):
print(encodingError)
}
}
)
我确实看到有问题的行有一个问题。尽量不要像这样使用枚举的原始值:
let stringValue = value as! String
multipartFormData.append(data: stringValue.data(using: .utf8)!, name: key)
我正在尝试为 Swift 3 和 Alamofire 4 转换代码,但我目前遇到以下错误:
Cannot call value of non-function type '((UInt) -> Data?)!'
在这一行:
multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)
请您对本案提出意见。我当前的代码如下。
Alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(imageData!, withName: "image", fileName: nowString + "To" + receiverString! + ".jpg", mimeType: "image/jpg")
for (key, value) in parameters {
multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)
}
},to:"uploadimgURL"
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _)
upload.responseString(completionHandler: { (response) in
debugPrint(response)
})
case .failure(let encodingError):
print(encodingError)
}
}
)
我确实看到有问题的行有一个问题。尽量不要像这样使用枚举的原始值:
let stringValue = value as! String
multipartFormData.append(data: stringValue.data(using: .utf8)!, name: key)