Skip to content

Commit 07060e1

Browse files
committed
Alamofire-SwiftyJSON for swift 2.0
Switching master branch of Alamofire and SwiftyJSON to swift 2.0 branch Update Alamofire-SwiftyJSON code in swift 2.0
1 parent e9d4acd commit 07060e1

4 files changed

Lines changed: 17 additions & 21 deletions

File tree

Alamofire

Submodule Alamofire updated 71 files

Source/Alamofire-SwiftyJSON.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension Request {
2323
:returns: The request.
2424
*/
2525
public func responseSwiftyJSON(completionHandler: (NSURLRequest, NSHTTPURLResponse?, SwiftyJSON.JSON, NSError?) -> Void) -> Self {
26-
return responseSwiftyJSON(queue:nil, options:NSJSONReadingOptions.AllowFragments, completionHandler:completionHandler)
26+
return responseSwiftyJSON(nil, options:NSJSONReadingOptions.AllowFragments, completionHandler:completionHandler)
2727
}
2828

2929
/**
@@ -37,19 +37,17 @@ extension Request {
3737
*/
3838
public func responseSwiftyJSON(queue: dispatch_queue_t? = nil, options: NSJSONReadingOptions = .AllowFragments, completionHandler: (NSURLRequest, NSHTTPURLResponse?, JSON, NSError?) -> Void) -> Self {
3939

40-
return response(queue: queue, responseSerializer: Request.JSONResponseSerializer(options: options), completionHandler: { (request, response, object, error) -> Void in
41-
40+
return response(queue: queue, responseSerializer: Request.JSONResponseSerializer(options: options), completionHandler: { (request, response, result) -> Void in
4241
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
43-
4442
var responseJSON: JSON
45-
if error != nil || object == nil{
46-
responseJSON = JSON.nullJSON
43+
if result.isFailure
44+
{
45+
responseJSON = JSON.null
4746
} else {
48-
responseJSON = SwiftyJSON.JSON(object!)
47+
responseJSON = SwiftyJSON.JSON(result.value!)
4948
}
50-
5149
dispatch_async(queue ?? dispatch_get_main_queue(), {
52-
completionHandler(self.request, self.response, responseJSON, error)
50+
completionHandler(self.request!, self.response, responseJSON, result.error)
5351
})
5452
})
5553
})

SwiftyJSON

Tests/Alamofire_SwiftyJSONTests.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ class Alamofire_SwiftyJSONTests: XCTestCase {
1717
func testJSONResponse() {
1818
let URL = "http://httpbin.org/get"
1919
let expectation = expectationWithDescription("\(URL)")
20-
21-
Alamofire.request(.GET, URL, parameters: ["foo": "bar"])
22-
.responseSwiftyJSON { (request, response, responseJSON, error) in
23-
expectation.fulfill()
24-
XCTAssertNotNil(request, "request should not be nil")
25-
XCTAssertNotNil(response, "response should not be nil")
26-
XCTAssertNil(error, "error should be nil")
27-
XCTAssertEqual(responseJSON["args"], SwiftyJSON.JSON(["foo": "bar"] as NSDictionary), "args should be equal")
28-
}
29-
20+
21+
Alamofire.request(.GET, URL, parameters: ["foo": "bar"]).responseSwiftyJSON({(request, response, responseJSON, error) in
22+
expectation.fulfill()
23+
XCTAssertNotNil(request, "request should not be nil")
24+
XCTAssertNotNil(response, "response should not be nil")
25+
XCTAssertNil(error, "error should be nil")
26+
XCTAssertEqual(responseJSON["args"], SwiftyJSON.JSON(["foo": "bar"] as NSDictionary), "args should be equal")
27+
})
3028
waitForExpectationsWithTimeout(10) { (error) in
3129
XCTAssertNil(error, "\(error)")
3230
}

0 commit comments

Comments
 (0)