Skip to content

Commit 717af7e

Browse files
committed
Adding documentation
1 parent a8ba055 commit 717af7e

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

Source/Alamofire-SwiftyJSON.swift

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,46 @@ import Foundation
1111
import Alamofire
1212
import SwiftyJSON
1313

14-
// MARK: - Request JSON
15-
16-
//public func requestJSON(method: Alamofire.Method, URLString: Alamofire.URLStringConvertible, parameters: [String: AnyObject]? = nil) -> Alamofire.Request {
17-
// return Alamofire.request(method, URLString , parameters: parameters, encoding: ParameterEncoding.JSON)
18-
//}
19-
20-
// MARK: - Request
14+
// MARK: - Request for Swift JSON
2115

2216
extension Alamofire.Request {
23-
24-
// MARK: - Swift JSON
2517

18+
/**
19+
Adds a handler to be called once the request has finished.
20+
21+
:param: completionHandler A closure to be executed once the request has finished. The closure takes 4 arguments: the URL request, the URL response, if one was received, the SwiftyJSON enum, if one could be created from the URL response and data, and any error produced while creating the SwiftyJSON enum.
22+
23+
:returns: The request.
24+
*/
2625
public func responseSwiftyJSON(completionHandler: (NSURLRequest, NSHTTPURLResponse?, SwiftyJSON.JSON, NSError?) -> Void) -> Self {
2726
return responseSwiftyJSON(completionHandler: completionHandler)
2827
}
29-
28+
29+
/**
30+
Adds a handler to be called once the request has finished.
31+
32+
:param: priority The dispatch priority / quality of service used to process the response handler. `DISPATCH_QUEUE_PRIORITY_DEFAULT` by default.
33+
:param: queue The queue on which the completion handler is dispatched.
34+
:param: options The JSON serialization reading options. `.AllowFragments` by default.
35+
:param: completionHandler A closure to be executed once the request has finished. The closure takes 4 arguments: the URL request, the URL response, if one was received, the SwiftyJSON enum, if one could be created from the URL response and data, and any error produced while creating the SwiftyJSON enum.
36+
37+
:returns: The request.
38+
*/
3039
public func responseSwiftyJSON(priority: Int = DISPATCH_QUEUE_PRIORITY_DEFAULT, queue: dispatch_queue_t? = nil, options: NSJSONReadingOptions = .AllowFragments, completionHandler: (NSURLRequest, NSHTTPURLResponse?, SwiftyJSON.JSON, NSError?) -> Void) -> Self {
3140

3241
return response(priority: priority, queue: queue, serializer: Alamofire.Request.JSONResponseSerializer(options: options), completionHandler: { (request, response, object, error) in
3342
dispatch_async(dispatch_get_global_queue(priority, 0), {
3443

3544
var responseJSON: SwiftyJSON.JSON
3645

37-
if (error != nil) {
46+
if error != nil {
3847
responseJSON = SwiftyJSON.JSON.Null(error)
3948
} else {
40-
responseJSON = SwiftyJSON.JSON(object: object!)
49+
if object != nil {
50+
responseJSON = SwiftyJSON.JSON(object: object)
51+
} else {
52+
responseJSON = SwiftyJSON.JSON.Null(nil)
53+
}
4154
}
4255

4356
dispatch_async(queue ?? dispatch_get_main_queue(), {

0 commit comments

Comments
 (0)