Untitled

mail@pastecode.io avatar
unknown
swift
a year ago
1.0 kB
2
Indexable
Never
import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        getFilms()
        DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
            self.getFilmsCompl()
        }
    }

    func getFilms() {
        Task {
            do {
                let films: [Film] = try await Network.shared.getFilms()
                print(films)
            } catch {
                print(error)
            }
        }
    }

    func getFilmsCompl() {
        Network.shared.getFilms { films, error in
            if let error {
                print(error)
            } else if let films {
                print(films)
            }
        }
    }

}


struct Result: Codable {
    var films: [Film]

    enum CodingKeys: String, CodingKey {
        case films = "results"
    }

}

struct Film: Codable {
    var title: String
    var producer: String
    var director: String
}