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

MVVM

2,298 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
  • Be the first to comment

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

×