Download - MVVM
MVVMRobert 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
NSManagedObjectContextNSManagedObject
Application
NSManagedObject Subclass
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 changes
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
NSPersistentStoreCoordinator NSManagedObjectModel
NSManagedObjectContextNSManagedObject
NSManagedObject Subclass
XML
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
Localization
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
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