diff --git a/AlamofireJsonToObjects/AlamofireJsonToObjects.swift b/AlamofireJsonToObjects/AlamofireJsonToObjects.swift index c4d76b6..dbca856 100644 --- a/AlamofireJsonToObjects/AlamofireJsonToObjects.swift +++ b/AlamofireJsonToObjects/AlamofireJsonToObjects.swift @@ -15,12 +15,13 @@ extension Request { /** Adds a handler to be called once the request has finished. + - parameter encoding: The string encoding. If `nil`, the string encoding will be determined from the server response, falling back to the default HTTP default character set,ISO-8859-1. - parameter completionHandler: A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 2 arguments: the response object (of type Mappable) and any error produced while making the request - returns: The request. */ - public func responseObject(completionHandler: (Result) -> Void) -> Self { - return responseObject(nil) { (request, response, data) in + public func responseObject(encoding: NSStringEncoding? = nil, completionHandler: (Result) -> Void) -> Self { + return responseObject(encoding: encoding) { (request, response, data: Alamofire.Result) -> Void in completionHandler(data) } } @@ -28,26 +29,14 @@ extension Request { /** Adds a handler to be called once the request has finished. - - parameter completionHandler: A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response object (of type Mappable), the raw response data, and any error produced making the request. - - - returns: The request. - */ - public func responseObject(completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result) -> Void) -> Self { - return responseObject(nil) { (request, response, data) in - completionHandler(request, response, data) - } - } - - /** - Adds a handler to be called once the request has finished. - - parameter queue: The queue on which the completion handler is dispatched. + - parameter encoding: The string encoding. If `nil`, the string encoding will be determined from the server response, falling back to the default HTTP default character set,ISO-8859-1. - parameter completionHandler: A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response object (of type Mappable), the raw response data, and any error produced making the request. - returns: The request. */ - public func responseObject(queue: dispatch_queue_t?, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result) -> Void) -> Self { - return responseString(completionHandler: { (response) -> Void in + public func responseObject(queue: dispatch_queue_t? = nil, encoding: NSStringEncoding? = nil, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result) -> Void) -> Self { + return responseString(encoding: encoding, completionHandler: { (response) -> Void in dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { dispatch_async(queue ?? dispatch_get_main_queue()) { switch response.result { @@ -67,12 +56,13 @@ extension Request { /** Adds a handler to be called once the request has finished. + - parameter encoding: The string encoding. If `nil`, the string encoding will be determined from the server response, falling back to the default HTTP default character set,ISO-8859-1. - parameter completionHandler: A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 2 arguments: the response array (of type Mappable) and any error produced while making the request - returns: The request. */ - public func responseArray(completionHandler: (Alamofire.Result<[T], NSError>) -> Void) -> Self { - return responseArray { (request, response, data) -> Void in + public func responseArray(encoding: NSStringEncoding? = nil, completionHandler: (Alamofire.Result<[T], NSError>) -> Void) -> Self { + return responseArray(encoding: encoding) { (request, response, data: Alamofire.Result<[T], NSError>) -> Void in completionHandler(data) } } @@ -80,24 +70,14 @@ extension Request { /** Adds a handler to be called once the request has finished. - - parameter completionHandler: A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response array (of type Mappable), the raw response data, and any error produced making the request. - - - returns: The request. - */ - public func responseArray(completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<[T], NSError>) -> Void) -> Self { - return responseArray(nil, completionHandler: completionHandler) - } - - /** - Adds a handler to be called once the request has finished. - - parameter queue: The queue on which the completion handler is dispatched. + - parameter encoding: The string encoding. If `nil`, the string encoding will be determined from the server response, falling back to the default HTTP default character set,ISO-8859-1. - parameter completionHandler: A closure to be executed once the request has finished and the data has been mapped to a swift Object. The closure takes 5 arguments: the URL request, the URL response, the response array (of type Mappable), the raw response data, and any error produced making the request. - returns: The request. */ - public func responseArray(queue: dispatch_queue_t?, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<[T], NSError>) -> Void) -> Self { - return responseString(completionHandler: { (response) -> Void in + public func responseArray(queue: dispatch_queue_t? = nil, encoding: NSStringEncoding? = nil, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<[T], NSError>) -> Void) -> Self { + return responseString(encoding: encoding, completionHandler: { (response) -> Void in dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { dispatch_async(queue ?? dispatch_get_main_queue()) { switch response.result {