4. • Tight coupling between View and Controller
• Hard to test interactions between View and
Controller
• Model can be testable
THE PROBLEM WITH
APPLE’s MVC
5. • An architecture pattern
• Model - View - ViewModel - Coordinator
• MVVMC treats UIViewController as a dumb
presenter - just a view
WHAT IS MVVMC ?
6. HOW IT WORKS ?
• Coordinator - owns View and/or another Coordinator(s), notifies Coordinator(s)
• View - owns ViewModel, notifies ViewModel (e.g button tap)
• ViewModel - owns Model, updates View, notifies Coordinator
7. Model
• Usually a protocol
• C.R.U.D - Create, Read, Update, Delete
• Uses functions, NOT properties
• Injected into ViewModel
8.
9. ViewModel
• Usually a class
• Independent of UIKit
• Injected into View and has no idea what the View is
• Business logic
• Operate with Model
• Provide presentation data to view and notify if that data has
changed
• Communicate states to Coordinator
13. COMPLEX FLOWS
• Many UIViewControllers
• Many options to choose where to go
• Does the UIViewController has to know what to
show next?
14.
15.
16. View
• UIViewController is also a View !!!
• Present human readable data
• Do the layout
• Inform ViewModel about interactions
17.
18. NOT ONLY UIViewController
• There is no rule about using ViewModels only
with UIViewController
• You can use ViewModels on almost on every UI
element
• UITextField, UIButton, …
19. NOT ONLY UIViewController
• This will decrease your code lines in ViewModel
• Makes code more distributed and increases
reusability
• Adds more flexibility to write unit tests
20.
21.
22. HOW IT COMES
TOGETHER?
• The GOD — AppCoordinator
• Only AppDelegate knows about AppCoordinator
• Desides what to show when app is finished
launching
23.
24.
25. UNIT TESTING
• ViewModel gets notified about events happened
in the view - we can test what is the result
• Test if presentation data is formatted correctly (e.g
convert Date object into formatted date string)
• Test if correct delegate method is called when it’s
needed to move on with the flow
• Test if errors are shown to view