Created
October 17, 2018 13:37
-
-
Save MP0w/82a9124c34f002a11a6f42416e9d1b52 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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