【问题标题】:Alamofire Swift 3 - Extra Argument in Call ErrorAlamofire Swift 3 - 调用错误中的额外参数
【发布时间】:2016-11-13 05:47:39
【问题描述】:

Xcode 迫使我将一些旧的 swift 2.3 语法更新到 3.0。 Alamofire 是 4.0.1。尝试构建项目时,由于调用中的额外参数错误而失败。

Alamofire.request(url, .GET, parameters: ["part":"snippet,contentDetails", "key": API_KEY,"maxResults":50, "channelId":channelId], encoding: ParameterEncoding.URL, headers: nil).responseJSON { (response) in

我该如何解决这个问题。它显示在项目中超过 6 个文件中。几乎相同的错误。

【问题讨论】:

标签: swift3 alamofire xcode8


【解决方案1】:

像下面这样调用

Alamofire.request(url, 
                  parameters: ["part":"snippet,contentDetails", "key": API_KEY,"maxResults":50, "channelId":channelId], 
                  encoding: URLEncoding.default)
         .responseJSON { (response) in
}

我希望它会起作用...有关更多信息,您可以查看链接 https://github.com/Alamofire/Alamofire#get-request-with-url-encoded-parameters

【讨论】:

    【解决方案2】:

    迁移 Swift 2.3Swift 3 后,您还需要更改为 Alamofire 库方法需要像这样调用

    斯威夫特 3

          let parameters = ["action":"cms", "id":"1"]
                
          Alamofire.request("Your webAPI link here", method: .get, parameters: parameters)
                    .responseJSON { response in
                        
                        print("Success: \(response.result.isSuccess)")
                        print("Response String: \(response.result.value)")
                        switch response.result {
                        case .success:
                            self.successGetTermsData(response.result.value! as AnyObject)
                        case .failure(let error):
                            self.failedGetData()
                            print(error)
                        }
                }
    

    为了更好地理解,您还可以查看这个 - Alamofire 4.0 Migration Guide

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 2018-03-03
      • 2023-03-21
      • 2018-08-26
      • 2017-01-22
      • 2019-02-23
      • 1970-01-01
      • 2015-09-13
      相关资源
      最近更新 更多