Search code examples
swiftalamofire

Alamofire 3.0 Request


I try to make a request to my server getting info form my API. Therefore I do:

Alamofire.request(.GET, requestURL).responseData { (response:NSHTTPURLResponse?, error: NSError?) -> Void in
            print(response)
        }

But I receive the error `Tuple pattern cannot match value of the non-tuple type 'Response'

Do I use the method in a wrong way?

The autocomplete shows me this:

Alamofire.request(.GET, requestURL).responseData(completionHandler: Response <NSData, NSError> -> void)

Solution

  • You can get the result from the Result type in Alamofire 3. You could unwrap it with switch-case by pattern matching, show you a example:

        Alamofire.request(.GET, requestURL).responseData { (response) -> Void in
            switch response.result {
            case .Success(let data):
                // Here you go
                print(data)
            case .Failure(let error):
                // Error handle
                print(error)
            }
        }