Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

"iOS: MVVMC" - Aleksandr Nikolajev from Mooncascade

1,737 views

Published on

Whats MVVMC?

Published in: Software
  • Be the first to comment

  • Be the first to like this

"iOS: MVVMC" - Aleksandr Nikolajev from Mooncascade

  1. 1. iOS: MVVMC MobileMonday 15 May 2017 Aleksandr Nikolajev iOS developer
  2. 2. ME • Graduated as material scientist in University of Tartu • Joined Mooncascade in 2015 • FinTech, transportation, multimedia, sports, utilities
  3. 3. AGENDA • Introduction to MVVMC and it’s pieces • Some examples • Unit testing
  4. 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. 5. • An architecture pattern • Model - View - ViewModel - Coordinator • MVVMC treats UIViewController as a dumb presenter - just a view WHAT IS MVVMC ?
  6. 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. 7. Model • Usually a protocol • C.R.U.D - Create, Read, Update, Delete • Uses functions, NOT properties • Injected into ViewModel
  8. 8. 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
  9. 9. Coordinator • Declared as a protocol • Handle navigation • Create View and inject ViewModel into it
  10. 10. COMPLEX FLOWS • Many UIViewControllers • Many options to choose where to go • Does the UIViewController has to know what to show next?
  11. 11. View • UIViewController is also a View !!! • Present human readable data • Do the layout • Inform ViewModel about interactions
  12. 12. 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, …
  13. 13. 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
  14. 14. HOW IT COMES TOGETHER? • The GOD — AppCoordinator • Only AppDelegate knows about AppCoordinator • Desides what to show when app is finished launching
  15. 15. 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
  16. 16. • Well distributed code • Good testability • Easy of use THE PROFIT
  17. 17. • MVVM-C A simple way to navigate
 http://tech.trivago.com/2016/08/26/mvvm-c-a- simple-way-to-navigate • iOS Architecture Patterns
 https://medium.com/ios-os-x-development/ios- architecture-patterns-ecba4c38de52 REFERENCES
  18. 18. THANK YOU!
  19. 19. If you wish to play with the code, clone this repo https://github.com/sasnik/MoMoMVVMC

×