MVVM and iOS use case
Hi I am new to MVVM as well as to iOS programming. I am trying to convert my sample app into MVVM pattern. Here is my simple use case-
I have one view controller class which holds information screen - InfoViewController. I has 4 informative labels with some text. Currently it is implementated in MVC pattern. viewDidLoad method binds iboutlets with text which is static. How can I convert this into MVVM? Here is my understanding
- InfoViewController will have InfoViewModel which will be initiliase in viewDidLoad
- Struct InfoViewModel will have a.firstLabelText b. secondLabelText and so on..
- In viewDidLoad method I will bind iboutlets with viewModel properties which will return text
Currently this text is static but it may come from web service in future so should I create model class here?
Is this correct way for this use case?作者: Kapil 的来源 发布者: 2017 年 12 月 27 日
The best way to bind your view and view model is to include a framework that supports you.
I use RxSwift to bind my view model to the view. A nice introduction to mvvvm with rx can be found at https://academy.realm.io/posts/slug-max-alexander-mvvm-rxswift作者: Johannes Starke 发布者: 28.12.2017 11:26