【问题标题】:Expression type '()' is ambiguous without more context表达式类型“()”在没有更多上下文的情况下是模棱两可的
【发布时间】:2016-09-14 08:23:47
【问题描述】:

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

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

但是,这告诉我“表达式类型 '()' 在没有更多上下文的情况下是模棱两可的。

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

【问题讨论】:

  • 你在哪一行有这个问题?
  • 这是什么 Alamofire 版本?我在任何上传方法重载中都找不到to 参数
  • @MarcoSantarossa:第一个
  • @marosoaie: 4.0.0
  • 我遇到了同样的问题。你搞清楚了吗?

标签: ios swift alamofire


【解决方案1】:

我对@9​​87654321@ 有错误的论据。这是有效的:

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

【讨论】:

  • 感谢您发布此信息。多亏了你的帖子,最简单的修复,从我超过 150 亿次搜索到愚蠢的 Swift 神秘错误的解决方案。干杯!
猜你喜欢
  • 1970-01-01
  • 2017-11-23
  • 2021-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多