Skip to content

Instantly share code, notes, and snippets.

@MP0w
Created October 17, 2018 13:37
Show Gist options
  • Save MP0w/82a9124c34f002a11a6f42416e9d1b52 to your computer and use it in GitHub Desktop.
Save MP0w/82a9124c34f002a11a6f42416e9d1b52 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
protocol Interactor: class {
associatedtype ModelType
var model: ModelType { get }
var modelDidUpdate: (() -> Void)? { get set }
}
protocol UpdateableView: class {
associatedtype ViewModelType
init(viewModel: ViewModelType)
func configure(with viewModel: ViewModelType)
}
// MARK: Binding
extension Interactor {
func bind<T: UpdateableView>(with viewController: T, factory: @escaping (_ interactor: Self, _ vc: T) -> Void) {
modelDidUpdate = { [weak self, weak viewController] in
guard let interactor = self, let viewController = viewController else {
return
}
factory(interactor, viewController)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment