Created
June 13, 2018 21:27
-
-
Save ARamy23/e85ab6f801d098c36d37755d0429df63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Response completion handler beautified. | |
typealias CallResponse<T> = ((ServerResponse<T>) -> Void)? | |
/// API protocol, The alamofire wrapper | |
protocol APIRequestHandler: HandleAlamoResponse { | |
/// Calling network layer via (Alamofire), this implementation can be replaced anytime in one place which is the protocol itself, applied anywhere. | |
/// | |
/// - Parameters: | |
/// - decoder: Codable confirmed class/struct, Model.type. | |
/// - completion: Results of the request, general errors cases handled. | |
/// - Returns: Void. | |
func send<T: CodableInit>(_ decoder: T.Type, completion: CallResponse<T>) | |
} | |
extension APIRequestHandler where Self: URLRequestConvertible { | |
func send<T: CodableInit>(_ decoder: T.Type, completion: CallResponse<T>) { | |
request(self).validate().responseData {(response) in | |
self.handleResponse(response, completion: completion) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment