【问题标题】:Cannot call value of non-function type 'HTTPURLResponse?' Alamofire 4, Swift 3无法调用非函数类型“HTTPURLResponse?”的值阿拉莫菲尔 4,斯威夫特 3
【发布时间】:2016-10-18 02:27:40
【问题描述】:

我想使用 Alamofire 通过 Mailgun 发送电子邮件。我正在使用下面的代码发送请求,但我在以.response 开头的线上收到错误Cannot call value of non-function type 'HTTPURLResponse?'

我该如何解决这个问题?我正在尝试复制此处找到的代码,但为 Swift 3 更新它。我正在尝试使用 Mailgun 和 Alamofire 发送电子邮件。

https://gist.github.com/makzan/11e8605f85352abf8dc1/

谢谢!

Alamofire.request(url, method: .post, parameters: parameters)
                                .authenticate(user: "api", password: key)
                                .response{ (request, response, data, error) in
                                    println(request)
                                    println(response)
                                    println(error)
                            }
                        }

【问题讨论】:

    标签: swift swift3 alamofire


    【解决方案1】:

    对于此类问题,值得查看Alamofire migration pages

    您会看到响应现在是这样处理的:

    // Alamofire 3
    Alamofire.request(.GET, urlString).response { request, response, data, error in
        print(request)
        print(response)
        print(data)
        print(error)
    }
    
    // Alamofire 4
    Alamofire.request(urlString).response { response in // method defaults to `.get`
        debugPrint(response)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      相关资源
      最近更新 更多