G. ABHISEK

iOS Developer at Kuliza
MVVM and (UI +VM+
Data) Binding
Our Journey
• MVVM ?

• Why MVVM?

• Thumb rules of MVVM.

• Hiccups of MVVM.

• Some common data + UIBinding scenarios

• Communications

• View Code Reusability
MVVM ?
Model View Model View

or
View Controller
Owns Owns
Updates VM

via callbacks
Configures the data and 

update
Updates VM of user actions

via callbacks
Why MVVM ?
Test Driven DevelopmentBuilds Segregated Code Avoids bulky controllers
Thumb Rules

of

MVVM
• View Model is responsible only for processing input to
output and logic required for driving the UI.

• View should be only responsible for UI handling.

• View should not interact with Data Model or vice-versa.

• View Model should not modify the UI.
Common HICCUPS while

Building MVVM
• Data Binding of complex UI components. 

Eg. Data source of TableViews and CollectionViews with a broad number
of cell types.

• Communication between various MVVM components ->
Delegates, Closures, KVO ..… OOPS!!!

• UI logic is sometimes messed in Model and ViewModel.
UI + ViewModel + DataBinding
Table or Collection View with multiple cell types
Cell 1 (CellVM1)
Cell N (CellVM2)
.
.
.
.
.
.
.
VM
Cell Enums associated with Cell VM
- Holds the data
- Holds the cell state
- Updates the view
model

of User Actions
Owns
Communication 

and
Binding
Closures
View
View

Model
Model
vm.eventHandler()
processCompleted(data: Any)
vm.update()
updateCompleted(data: Any)
2 - Way Binding
• KVO

• RXSwift

• Reactive design pattern
https://codeburst.io/swift-mvvm-two-way-binding-win-b447edc55ff5
MVVM …..!!!

View Code Reusability
ViewModel 1
ViewModel

Representable
- Inputs to the VM
- Outputs to VM
- Any generic
methods
ViewModel 2
ViewModel 3
Confirm
View
VM Instance



Its a
VMRepresentableType!
Protocols to Rescue ..
Thank You !!

MVVM in iOS presentation