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 func fetchMovies(onSuccess: ([Movie]) -> Void) { | |
| let exampleMovie = Movie(title: "Movie title", year: "2017", genre: ["Action", "Adventure"]) | |
| onSuccess([exampleMovie]) | |
| } |
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 | |
| struct Movie { | |
| let title: String | |
| let year: String | |
| let genre: [String] | |
| init(title: String, year: String, genre: [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
| { | |
| "title": "Movie Title", | |
| "year": "2017", | |
| "genre": [ | |
| "Action", | |
| "Adventure" | |
| ] | |
| } |
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
| self.viewController = MoviesViewController() | |
| self.navigationController.pushViewController(self.viewController, animated: false) |
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 UIKit | |
| final class MoviesViewCoordinator { | |
| private let navigationController: UINavigationController | |
| init(navigationController: UINavigationController) { | |
| self.navigationController = navigationController | |
| } |
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
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "MovieCell") | |
| self.dataSource = MoviesTableViewDataSource() | |
| self.tableView.dataSource = self.dataSource | |
| if let viewModel = self.viewModel { |
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 set(viewModel: MoviesViewModel) { | |
| self.viewModel = viewModel | |
| if self.isViewLoaded { | |
| self.bind(viewModel: viewModel) | |
| } | |
| } | |
| private func bind(viewModel: MoviesViewModel) { |
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 UIKit | |
| final class MoviesTableViewDataSource: NSObject, UITableViewDataSource { | |
| var viewModels: [MovieCellViewModel] = [] | |
| func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
| return self.viewModels.count | |
| } |
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
| struct MoviesViewModel { | |
| let movies: [MovieCellViewModel] | |
| init(movies: [MovieCellViewModel]) { | |
| self.movies = movies | |
| } | |
| } | |
| struct MovieCellViewModel { |
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
| #!/bin/bash | |
| realpath() { | |
| [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" | |
| } | |
| FILE_PATH=$(realpath $0) | |
| # File directory path | |
| DIR_NAME=$(dirname "${FILE_PATH}") |