Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trupin/31304d5b568d0ee3b0a81983c2334654 to your computer and use it in GitHub Desktop.
Save trupin/31304d5b568d0ee3b0a81983c2334654 to your computer and use it in GitHub Desktop.
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