简体   繁体   中英

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:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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