sesc360
sesc360

Reputation: 3255

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)

Upvotes: 0

Views: 294

Answers (1)

yuhua
yuhua

Reputation: 1249

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

Upvotes: 3

Related Questions