Skip to content

Commit df7ca23

Browse files
authored
Merge pull request #2 from k-angama/feature/update
fix: initialize viewModel
2 parents 55cf66c + e969b79 commit df7ca23

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CleanArchKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = 'CleanArchKit'
4-
s.version = '0.1.1'
4+
s.version = '0.1.2'
55
s.swift_version = "5.0"
66
s.summary = 'An iOS library to create a project with the Clean Architecture using Router and MVVM pattern.'
77

CleanArchKit/CleanArchKit/Base/BaseViewController.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ open class BaseViewController<T: ViewModelProtocol>: UIViewController, ViewContr
1515
*/
1616
public var viewModel:T!
1717

18+
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
19+
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
20+
initViewModel()
21+
}
22+
23+
required public init(coder: NSCoder) {
24+
super.init(coder: coder)!
25+
initViewModel()
26+
}
1827

1928
open override func viewDidLoad() {
2029
super.viewDidLoad()
21-
viewModel = T(viewController: self)
22-
if(self.conforms(to: DIProtocol.self) && self.responds(to: #selector(DIProtocol.di))) {
23-
self.perform(#selector(DIProtocol.di))
24-
}
2530
setupUI()
2631
setupBindings()
2732
setupObservers()
@@ -30,6 +35,13 @@ open class BaseViewController<T: ViewModelProtocol>: UIViewController, ViewContr
3035
viewModel.observers()
3136
}
3237

38+
private func initViewModel() {
39+
viewModel = T(viewController: self)
40+
if(self.conforms(to: DIProtocol.self) && self.responds(to: #selector(DIProtocol.di))) {
41+
self.perform(#selector(DIProtocol.di))
42+
}
43+
}
44+
3345
/**
3446
* Set data binding in the view controller
3547
*/
@@ -44,6 +56,7 @@ open class BaseViewController<T: ViewModelProtocol>: UIViewController, ViewContr
4456
* Manage user interface here
4557
*/
4658
open func setupUI() {}
59+
4760

4861
deinit {
4962
print("deinit ViewController - \(Self.debugDescription())")

0 commit comments

Comments
 (0)