Skip to content

Instantly share code, notes, and snippets.

View trupin's full-sized avatar

Theophane RUPIN trupin

View GitHub Profile
struct Page<Model: Decodable>: Decodable {
let page: UInt
let total_results: UInt
let total_pages: UInt
let results: [Model]
}
final class MovieManager {
func getDiscoverMovies(_ completion: @escaping (Page<Movie>?) -> Void) {
let completionOnMainThread = { result in
DispatchQueue.main.async {
completion(result)
}
}
// MARK: - Error
enum MovieManagerError: Error {
case oops
}
// MARK: - Manager
protocol MovieManaging {
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
private let dependencies: AppDelegateDependencyResolver = AppDelegateDependencyContainer()
// weaver: homeViewController = HomeViewController <- UIViewController
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
import UIKit
final class MovieTableViewCell: UITableViewCell {
struct ViewModel {
let title: String
}
func bind(_ viewModel: ViewModel) {
textLabel?.text = viewModel.title
struct Movie: Decodable {
let vote_count: UInt
let id: UInt
let video: Bool
let vote_average: Float
let title: String
let popularity: Float
let poster_path: String
let original_language: String
let original_title: String
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
final class MoviesViewController: UIViewController {
private let dependencies: MoviesViewControllerDependencyResolver
// weaver: movieManager <- MovieManaging
required init(injecting dependencies: MoviesViewControllerDependencyResolver) {
self.dependencies = dependencies
super.init(nibName: nil, bundle: nil)
}
final class MovieManagerTests: XCTestCase {
private var storeSpy: KeyValueStoreSpy!
private var clientSpy: ClientSpy!
private var movieManager: MovieManaging!
override func setUp() {
super.setUp()
final class KeyValueStoreSpy: KeyValueStoring {
// MARK: - Records
private(set) var keyRecords = [String]()
private(set) var valueRecords = [StoreValueRepresentable]()
// MARK: - Stubs