Skip to content

Instantly share code, notes, and snippets.

protocol MyProtocol {
var sharedInstance: Any?  { get set }
}
final class DefaultMyProtocol: MyProtocol {
var sharedInstance: Any? = nil
}
final class MyProtocolSharedInstanceSetter {
private let myProtocol: MyProtocol
init(myProtocol: MyProtocol, myApi: MyApi) {
self.myProtocol = myProtocol
myApi.getRequest(onCompletion: { [weak self] in myProtocol.sharedInstance = $0 }
}
}
protocol MyProtocol: class {
var sharedInstance: Any? { get set }
}
#!/bin/bash
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
FILE_PATH=$(realpath $0)
# File directory path
DIR_NAME=$(dirname "${FILE_PATH}")
struct MoviesViewModel {
let movies: [MovieCellViewModel]
init(movies: [MovieCellViewModel]) {
self.movies = movies
}
}
struct MovieCellViewModel {
import Foundation
import UIKit
final class MoviesTableViewDataSource: NSObject, UITableViewDataSource {
var viewModels: [MovieCellViewModel] = []
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.viewModels.count
}
func set(viewModel: MoviesViewModel) {
self.viewModel = viewModel
if self.isViewLoaded {
self.bind(viewModel: viewModel)
}
}
private func bind(viewModel: MoviesViewModel) {
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 {
import Foundation
import UIKit
final class MoviesViewCoordinator {
private let navigationController: UINavigationController
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}