ios - 表达式类型 '()' 在没有更多上下文的情况下不明确

标签 ios swift alamofire

我正在尝试使用此代码(其中 photo.image 是 UIImage)通过 Alamofire 进行上传

let imageData = UIImageJPEGRepresentation(photo.image, 1.0)

Alamofire.upload(
    multipartFormData: { multipartFormData in
        multipartFormData.append(data: imageData!, withName: "unicorn")
    },
    to: "https://httpbin.org/post",
    encodingCompletion: { encodingResult in
        switch encodingResult {
        case .success(let upload, _, _):
            upload.responseJSON { response in
                debugPrint(response)
            }
        case .failure(let encodingError):
            print(encodingError)
        }
    }
)

但是,这告诉我“表达式类型‘()’在没有更多上下文的情况下不明确。

我不确定我在这里做错了什么,希望得到一些建议。

最佳答案

我对 multipartFormData 的参数有误。这是有效的方法:

multipartFormData: { multipartFormData in
                    multipartFormData.append(imageData!, withName: "photo", fileName: "image.jpg", mimeType: "image/jpg")
                },

关于ios - 表达式类型 '()' 在没有更多上下文的情况下不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39485735/

相关文章:

jquery - iPhone 模拟器理解第一个 "click"jQuery 事件,但不理解第二个

ios - JSON 到自定义对象数组 (Swift)

ios - Google Place Request_Denied 恐怖

ios - 在ios应用程序swift中使用Azure表存储(NoSQL)

iOS:通过 CATransform3DRotate 旋转时跳转 uiview

ios - 将字典数组转换为字典并初始化模型

ios - 在 TableView 单元格中通过alamofire解析json数据

swift - 使用 SwiftyJSON 和 Alamofire 循环 JSON

ios - 在 iOS 中,Gamekitframework 在发送消息方面是否比 multipeerconnectivity 框架更快?

ios - 获取网络(非设备)IP地址iOS swift