Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
...
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):
...
private let database: Database!
init(apiClient: APIClient, database: Database) {
self.apiClient = apiClient
self.database = database
}
...
enum RepositoryType {
case local, remote
}
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? {
# 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
// 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"),
import UIKit
final class ViewController: UIViewController {
let repository = Repository(apiClient: APIClient())
override func viewDidLoad() {
super.viewDidLoad()
repository.getFlights { (result) in
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 {
// <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\":\"МОСКВА(ШЕРЕМЕТЬЕВО) \"
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")!)