Kapil
Kapil

Reputation: 143

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

  1. InfoViewController will have InfoViewModel which will be initiliase in viewDidLoad
  2. Struct InfoViewModel will have a.firstLabelText b. secondLabelText and so on..
  3. 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?

Upvotes: 2

Views: 1109

Answers (1)

Johannes
Johannes

Reputation: 586

The best way to bind your view and view model is to include a framework that supports you.

E.g:

https://github.com/ReactiveX/RxSwift

https://github.com/ReactiveKit/ReactiveKit

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

Upvotes: 2

Related Questions