简体   繁体   中英

Cannot call value of non-function type 'HTTPURLResponse?' Alamofire 4, Swift 3

I want to use Alamofire to send an email with Mailgun. I'm using the below code to send the request, but I'm getting error Cannot call value of non-function type 'HTTPURLResponse?' on line starting with .response .

How can I fix this? I'm trying to replicate the code found here but update it for Swift 3. I'm trying to send an email using Mailgun and Alamofire.

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

Thanks!

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

It's worth taking a look at the Alamofire migration pages for these sorts of issues.

You'll see there that responses are now handled like so:

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

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