MVVM

1,787 views
1,567 views

Published on

In this presentation I implement the MVVM pattern by combining Core Data and Reactive Cocoa. The MVVM pattern can use any data storage and binding libraries, but I chose Core Data and Reactive Cocoa since they are common on iOS. Demo at https://github.com/rob-brown/Demos/tree/master/MVVMDemo.

Published in: Technology, Business
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,787
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

MVVM

  1. 1. MVVM Robert Brown @robby_brown @robert_brown @rob-brown
  2. 2. Outline 1. Core Data 2. Reactive Cocoa 3. MVVM
  3. 3. Core Data
  4. 4. What is Core Data? Intimidating An amazing data persistence framework Not a database
  5. 5. Core Data Layers XML SQLite Binary In Memory Custom NSPersistentStore NSPersistentStoreCoordinator NSManagedObjectModel NSManagedObjectContext NSManagedObject Application NSManagedObject Subclass
  6. 6. Core Data Stack Persistent Store Coordinator Managed Object Context(s) Persistent Store(s) Managed Object Model
  7. 7. More on Core Data Intro to Core Data Core Data: Data Storage Management for iOS, OS X, and iCloud RBCoreDataStack
  8. 8. Reactive Cocoa
  9. 9. What is Reactive Cocoa? Made by GitHub A functional reactive programming (FRP) framework Provides the bindings in MVVM
  10. 10. What is Reactive Cocoa? Binds properties together Eliminates the need for mutable state UI updates automatically as data changes
  11. 11. More on Reactive Cocoa Intro to Reactive Cocoa Functional Reactive Programming on iOS ReactiveCocoa
  12. 12. MVVM
  13. 13. What is MVVM? Model-View-ViewModel A variant of MVC Uses an adapter between the view and model
  14. 14. What is MVVM? View View Model Model Owns Owns UpdatesUpdates
  15. 15. What is MVVM? Data Model ViewModel Network ViewController View Data Storage
  16. 16. Application Stack ViewModel Network ViewController View SQLite Binary In Memory Custom NSPersistentStore NSPersistentStoreCoordinator NSManagedObjectModel NSManagedObjectContext NSManagedObject NSManagedObject Subclass XML
  17. 17. Model Represents the data layer Can be built with any technology Ex. Core Data, SQLite, JSON, PList, memory-only
  18. 18. View Handles layout and presentation of data In iOS, the “View” refers to both UIViews and UIViewControllers
  19. 19. ViewModel An adapter between the View and Model Contains all the business logic Uses bindings to pass data around
  20. 20. ViewModel Acts like a model Hides the real model logic from the view
  21. 21. ViewModel Some responsibilities: Kick off network and database requests Show/hide information Data/number formatting Localization
  22. 22. Benefits of MVVM View models are testable View models can be used like models View models are (mostly) platform-agnostic View and view controllers are simpler
  23. 23. Related Patterns Model Operation View Event (MOVE) Model View Presenter (MVP) Presentation Model (PM)
  24. 24. Questions?
  25. 25. Demo
  26. 26. Want to Learn More? ReactiveViewModel Functional Reactive Programming on iOS Wikipedia
  27. 27. Want to Learn More? ! Ash Furrow C-41 Functional Reactive Pixels

×