Skip to content

Instantly share code, notes, and snippets.

@catalinaturlea
Last active February 2, 2023 00:39
Show Gist options
  • Select an option

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

Select an option

Save catalinaturlea/1430433f85d5405e15e6 to your computer and use it in GitHub Desktop.
AlamofireWrapper - redefining enums
@objc public enum RequestMethod: NSInteger {
case OPTIONS = 0, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT
}
@objc public enum RequestParameterEncoding: NSInteger {
case URL, URLEncodedInURL, JSON
}
public class AlamofireWrapper: NSObject {
// .....
// Maps the custom RequestMethod enum values to the Alamofire.Method values
private class func translateMethod(method: RequestMethod) -> Alamofire.Method {
switch method {
case .GET:
return .GET
case .POST:
return .POST
case .DELETE:
return .DELETE
case .HEAD:
return .HEAD
case .PUT:
return .PUT
case .PATCH:
return .PATCH
case .TRACE:
return .TRACE
case .CONNECT:
return .CONNECT
case .OPTIONS:
return .OPTIONS
}
}
// Maps the custom RequestParameterEncoding enum values to the Alamofire.ParameterEncoding values
private class func translateEncoding(encoding: RequestParameterEncoding) -> Alamofire.ParameterEncoding {
switch encoding {
case .JSON:
return .JSON
case .URLEncodedInURL:
return .URLEncodedInURL
case .URL:
return .URL
}
}
// .....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment