-
Notifications
You must be signed in to change notification settings - Fork 1
/
MVVMÇ.swift
42 lines (32 loc) · 1.05 KB
/
MVVMÇ.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)
}
}
}
class Coordinator {
private weak var _rootViewController: UIViewController?
var rootViewController: UIViewController {
return _rootViewController ?? createRootViewController()
}
func createRootViewController() -> UIViewController {
fatalError("createRootViewController not implemented")
}
}