Created
April 25, 2018 01:09
-
-
Save trupin/31304d5b568d0ee3b0a81983c2334654 to your computer and use it in GitHub Desktop.
This file contains 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
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