Skip to content

Instantly share code, notes, and snippets.

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