If you see the documentation in the Swift2.0 branch, you can see that the responseJSON function has been changed, as the error says, now it has three parameters, but you can also catch the error, let's take a look:
public func responseJSON( options options: NSJSONReadingOptions = .AllowFragments, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<AnyObject>) -> Void) -> Self { return response( responseSerializer: Request.JSONResponseSerializer(options: options), completionHandler: completionHandler ) }
Now it returns enum Result<AnyObject> and according to the doc:
Used to represent whether a request was successful or encountered an error. - Success: The request and all post processing operations were successful resulting in the serialization of the provided associated value. - Failure: The request encountered an error resulting in a failure. The associated values are the original data provided by the server as well as the error that caused the failure.
And it has a property called error with the following document:
/// Returns the associated error value if the result is a failure, `nil` otherwise. public var error: ErrorType? { switch self { case .Success: return nil case .Failure(_, let error): return error } }
Then, if you run this test inside Alamofire, you can see how to get the error correctly:
func testThatResponseJSONReturnsSuccessResultWithValidJSON() { // Given let URLString = "https://httpbin.org/get" let expectation = expectationWithDescription("request should succeed") var request: NSURLRequest? var response: NSHTTPURLResponse? var result: Result<AnyObject>! // When Alamofire.request(.GET, URLString, parameters: ["foo": "bar"]) .responseJSON { responseRequest, responseResponse, responseResult in request = responseRequest response = responseResponse result = responseResult expectation.fulfill() } waitForExpectationsWithTimeout(defaultTimeout, handler: nil) // Then XCTAssertNotNil(request, "request should not be nil") XCTAssertNotNil(response, "response should not be nil") XCTAssertTrue(result.isSuccess, "result should be success") XCTAssertNotNil(result.value, "result value should not be nil") XCTAssertNil(result.data, "result data should be nil") XCTAssertTrue(result.error == nil, "result error should be nil") }
UPDATE
Alamofire 3.0.0 introduces a Response framework. All response serializers (except Response ) return a generic Response construct.
public struct Response<Value, Error: ErrorType> {
So you can call it like this:
Alamofire.request(.GET, "http://httpbin.org/get") .responseJSON { response in debugPrint(response) }
You can learn more about the migration process in the Alamofire 3.0 Migration Guide .
Hope this helps you.