简体   繁体   English

无法调用非功能类型'(((UInt)-> Data?)!' 与Alamofire 4

[英]Cannot call value of non-function type '((UInt) -> Data?)!' with Alamofire 4

I'm trying convert code for Swift 3 and Alamofire 4, and I'm currently struggling with the following error: 我正在尝试为Swift 3和Alamofire 4转换代码,而我目前正遇到以下错误:

Cannot call value of non-function type '((UInt) -> Data?)!'

at this line: 在这一行:

multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)

Please give your advice for this case. 对于这种情况,请提供您的建议。 My current code is below. 我当前的代码如下。

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)
        }
    }
)

I do see one issue with the line in question. 我确实在所讨论的行中看到一个问题。 Try not using the raw value of the enum like so: 尝试不使用枚举的原始值,如下所示:

let stringValue = value as! String
multipartFormData.append(data: stringValue.data(using: .utf8)!, name: key)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM