Skip to content

Commit

Permalink
Merge pull request #16 from tamir7/master
Browse files Browse the repository at this point in the history
Added encoding optional param to responseObject and responseArray fun…
  • Loading branch information
evermeer committed Mar 14, 2016
2 parents dc987b4 + 722b0c7 commit 8e62077
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions AlamofireJsonToObjects/AlamofireJsonToObjects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,28 @@ 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<T:EVObject>(completionHandler: (Result<T, NSError>) -> Void) -> Self {
return responseObject(nil) { (request, response, data) in
public func responseObject<T:EVObject>(encoding: NSStringEncoding? = nil, completionHandler: (Result<T, NSError>) -> Void) -> Self {
return responseObject(encoding: encoding) { (request, response, data: Alamofire.Result<T, NSError>) -> Void in
completionHandler(data)
}
}

/**
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<T:EVObject>(completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<T, NSError>) -> 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<T:EVObject>(queue: dispatch_queue_t?, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<T, NSError>) -> Void) -> Self {
return responseString(completionHandler: { (response) -> Void in
public func responseObject<T:EVObject>(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 {
Expand All @@ -67,37 +56,28 @@ 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<T:EVObject>(completionHandler: (Alamofire.Result<[T], NSError>) -> Void) -> Self {
return responseArray { (request, response, data) -> Void in
public func responseArray<T:EVObject>(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)
}
}

/**
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<T:EVObject>(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<T:EVObject>(queue: dispatch_queue_t?, completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<[T], NSError>) -> Void) -> Self {
return responseString(completionHandler: { (response) -> Void in
public func responseArray<T:EVObject>(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 {
Expand Down

0 comments on commit 8e62077

Please sign in to comment.