-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMVVMProtocol.swift
62 lines (48 loc) · 1.67 KB
/
MVVMProtocol.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// MVVMProtocol.swift
// mvvmTest
//
// Created by hanwe on 2021/02/08.
// Copyright © 2021 hanwe All rights reserved.
//
import RxSwift
protocol MVVMViewController: class {
associatedtype MVVMViewModelClassType: MVVMViewModel
associatedtype SelfType: MVVMViewController
var disposeBag: DisposeBag { get set }
var isViewModelBinded: Bool { get set }
var viewModel: MVVMViewModelClassType! { get set }
func bind(viewModel: MVVMViewModel)
func bindingViewModel<T: MVVMViewModel>(viewModel: T) -> T
static func makeViewController(viewModel: MVVMViewModelClassType) -> SelfType?
}
extension MVVMViewController {
@discardableResult func bindingViewModel<T: MVVMViewModel>(viewModel: T) -> T {
bind(viewModel: viewModel)
viewModel.subscribeInputs()
self.isViewModelBinded = true
return viewModel
}
}
protocol MVVMView: class {
associatedtype MVVMViewModelClassType: MVVMViewModel
associatedtype SelfType: MVVMView
var disposeBag: DisposeBag { get set }
var isViewModelBinded: Bool { get set }
var viewModel: MVVMViewModelClassType! { get set }
func bind(viewModel: MVVMViewModel)
func bindingViewModel<T: MVVMViewModel>(viewModel: T) -> T
static func makeView(viewModel: MVVMViewModelClassType) -> SelfType?
}
extension MVVMView {
@discardableResult func bindingViewModel<T: MVVMViewModel>(viewModel: T) -> T {
bind(viewModel: viewModel)
viewModel.subscribeInputs()
self.isViewModelBinded = true
return viewModel
}
}
protocol MVVMViewModel: class {
var disposeBag: DisposeBag { get set }
func subscribeInputs()
}