Last active
December 5, 2020 18:00
-
-
Save hardik-trivedi/4f1fbec2b65b3859210cbf74f5733fb5 to your computer and use it in GitHub Desktop.
Demonstrating how NovelCovidApiClient can be used in iOS
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
import Foundation | |
import shared | |
struct CountryListApiManager: CountryListApiManaging { | |
let client: NovelCovidApiClient | |
init(client: NovelCovidApiClient) { | |
self.client = client | |
} | |
func fetchCountryList(completion: @escaping (APIResult<[CountryViewModel]>) -> ()) { | |
completion(.success([])) | |
// This will call API | |
try? client.getAffectedCountries { (buisnessCountryModels, error) in | |
DispatchQueue.main.async { | |
if let _ = error { | |
completion(.failure(.failedTofech)) | |
} else { | |
guard let buisnessCountryModels = buisnessCountryModels else { | |
return completion(.failure(.noData)) | |
} | |
completion(.success(buisnessCountryModels.map { CountryViewModel(apiModel: $0) })) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment