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
... | |
func getFlights(_ type: RepositoryType, _ completion: @escaping ((Result<[FlightData]>) -> Void)) { | |
switch type { | |
case .local: | |
completion(.success(database.get())) | |
case .remote: | |
let resource = Resource(url: URL(string: "https://desolate-beyond-86929.herokuapp.com/arrival")!) | |
apiClient.load(resource) { [weak self] (result) in | |
switch result { | |
case .success(let data): |
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
... | |
private let database: Database! | |
init(apiClient: APIClient, database: Database) { | |
self.apiClient = apiClient | |
self.database = database | |
} | |
... |
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
enum RepositoryType { | |
case local, remote | |
} |
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 RealmSwift | |
// TODO: - Move to the separated file Flight.swift (Realm folder) | |
class Flight: Object { | |
@objc dynamic var airline: String = "" | |
@objc dynamic var flight: String = "" | |
@objc dynamic var actualTime: String = "" | |
override static func primaryKey() -> String? { |
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
# Uncomment the next line to define a global platform for your project | |
# platform :ios, '9.0' | |
target 'JsonCoddableUrlSession' do | |
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks | |
use_frameworks! | |
# Pods for JsonCoddableUrlSession | |
pod 'RealmSwift' | |
# Add this line |
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
// JsonCoddableUrlSession.FlightData(Airline: "BELAVIA", Flight: "B2734", ActualTime: "05:37"), JsonCoddableUrlSession.FlightData(Airline: "BELAVIA", Flight: "B2736", ActualTime: "05:46"), JsonCoddableUrlSession.FlightData(Airline: "BELAVIA", Flight: "B2848", ActualTime: "06:58"), JsonCoddableUrlSession.FlightData(Airline: "BELAVIA", Flight: "B2944", ActualTime: "06:51"), |
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 UIKit | |
final class ViewController: UIViewController { | |
let repository = Repository(apiClient: APIClient()) | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
repository.getFlights { (result) in |
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 | |
// TODO: - Move to the separated file FlightData.swift | |
struct FlightData: Codable { | |
let Airline: String | |
let Flight: String | |
let ActualTime: String | |
} | |
final class Repository { |
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
// <JsonCoddableUrlSession.ViewController: 0x7f925bd1bd10> retrive data: Optional("[{\"Airline\":\"AEROFLOT\",\"ScheduleTime\":\"00:25\",\"ActualTime\":\"00:11\",\"Flight\":\"SU1834\",\"DepartureAirport\":\"МОСКВА(ШЕРЕМЕТЬЕВО) \",\"Sector\":\"5\",\"Status\":\"\\u003cspan style=\\\"color:green\\\"\\u003eПРИБЫЛ\\u003c/span\\u003e\"},{\"Airline\":\"AUSTRIAN AIRLINES\",\"ScheduleTime\":\"00:40\",\"ActualTime\":\"00:15\",\"Flight\":\"OS689\",\"DepartureAirport\":\"ВЕНА \",\"Sector\":\"4\",\"Status\":\"\\u003cspan style=\\\"color:green\\\"\\u003eПРИБЫЛ\\u003c/span\\u003e\"},{\"Airline\":\"AEROFLOT\",\"ScheduleTime\":\"02:20\",\"ActualTime\":\"02:14\",\"Flight\":\"SU1838\",\"DepartureAirport\":\"МОСКВА(ШЕРЕМЕТЬЕВО) \" |
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 UIKit | |
final class ViewController: UIViewController { | |
let apiClient = APIClient() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let resource = Resource(url: URL(string: "https://desolate-beyond-86929.herokuapp.com/arrival")!) |