Skip to content

Instantly share code, notes, and snippets.

@hardik-trivedi
Last active December 5, 2020 18:00
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 hardik-trivedi/4f1fbec2b65b3859210cbf74f5733fb5 to your computer and use it in GitHub Desktop.
Save hardik-trivedi/4f1fbec2b65b3859210cbf74f5733fb5 to your computer and use it in GitHub Desktop.
Demonstrating how NovelCovidApiClient can be used in iOS
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