Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension ClientProtocol {
func get<Model>(path: String, completion: @escaping (Result<Model, ClientError>) -> Void) where Model: Decodable {
get(path: path) { (result: Result<Data, ClientError>) in
switch result {
case .success(let data):
do {
let model = try JSONDecoder().decode(Model.self, from: data)
completion(.success(model))
} catch {
completion(.failure(.parsing(error)))
}
case .failure(let error):
completion(.failure(error))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment