Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created November 8, 2018 04:13
Show Gist options
  • Save vialyx/951fc8a9f8f29ae8690a31025af17acc to your computer and use it in GitHub Desktop.
Save vialyx/951fc8a9f8f29ae8690a31025af17acc to your computer and use it in GitHub Desktop.
import Foundation
// TODO: - Move to the separated file FlightData.swift
struct FlightData: Codable {
let Airline: String
let Flight: String
let ActualTime: String
}
final class Repository {
private let apiClient: APIClient!
init(apiClient: APIClient) {
self.apiClient = apiClient
}
func getFlights(_ completion: @escaping ((Result<[FlightData]>) -> Void)) {
let resource = Resource(url: URL(string: "https://desolate-beyond-86929.herokuapp.com/arrival")!)
apiClient.load(resource) { (result) in
switch result {
case .success(let data):
do {
let items = try JSONDecoder().decode([FlightData].self, from: data)
completion(.success(items))
} catch {
completion(.failure(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