Skip to content

Instantly share code, notes, and snippets.

@catalinaturlea
Last active May 22, 2020 15:14
Show Gist options
  • Select an option

  • Save catalinaturlea/bc7d8e4b05f5a438e237 to your computer and use it in GitHub Desktop.

Select an option

Save catalinaturlea/bc7d8e4b05f5a438e237 to your computer and use it in GitHub Desktop.
Request wrapper
public class AlamofireWrapper: NSObject {
// MARK: - Request Methods
/**
Creates a request using the shared manager instance for the specified method, URL string, parameters, and
parameter encoding.
- parameter method: The HTTP method.
- parameter URLString: The URL string.
- parameter parameters: The parameters.
- parameter encoding: The parameter encoding. `.URL` by default.
- parameter headers: The HTTP headers.
- parameter success: The block to be executed in case the request succeeds.
- parameter failure: The block to be executed in case the request fails.
*/
public class func performJSONRequest(
method: RequestMethod,
URLString: String,
parameters: [String: NSObject]?,
encoding: RequestParameterEncoding = .URL,
headers: [String: String]?,
success: (request: NSURLRequest?, response: NSHTTPURLResponse?, json: [NSObject: AnyObject]?) -> (),
failure: (request: NSURLRequest?, response: NSHTTPURLResponse?, error: NSError?) -> ()) {
let method = translateMethod(method)
let encoding = translateEncoding(encoding)
let request = Alamofire.request(method, URLString, parameters: parameters, encoding: encoding, headers: headers)
request.responseJSON { (response) -> Void in
parseResponse(response, success: success, failure: failure)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment