Upload
fwdays
View
108
Download
1
Tags:
Embed Size (px)
Citation preview
MASSIVE VIEW CONTROLLER
UIViewController
UIKit
Network Data storage
Business logic
Custom interface
System Interaction
5
APPLE MVC
UIViewController
UIKit
Network Data storage
Business logic
Custom interface
System Interaction
6
MVVM (RICH VIEW)
UIViewController
UIKit
Network Data storage
Business logic
Custom interface
System Interaction
@interface MyView: UIView
id<MyViewModel>
7
MVVM (RICH VIEW)
UIViewController
UIKit
Network Data storage
Business logic
Custom interface
System Interaction
@interface MyView: UIView
id<MyViewModel>
8
MVVM (RICH VIEW) + RAC
UIViewController
UIKit
Network Data storage
Business logic
Custom interface
System Interaction
@interface MyView: UIView
id<MyViewModel>
9
MVVM (RICH VIEW) + RAC
UIViewController
UIKit
Network Data storage
Business logic
Custom interface
System Interaction
@interface MyView: UIView
id<MyViewModel>
10
HOW TO ACHIEVE?
Destination owns a Source.
Destination calls a Source.
Destination look at Source state.
Destination is derived from Source.
16
DECOMPOSITION IS A KEY
View decomposed to UIViews, UIViewControllers, DataSources, Delegates, Managers, Storyboards…
View Model decomposed to View Models.
Model decomposed to Core, Services, Facades.
21
CODE / LAYER DISTRIBUTION
0
25
50
75
100
Content feed Content editor Offline content Offline with sync
View ViewModel Model
22
VIEW LAYER
Storyboard backed, XIB backed, code - no matter.
Layout.
Localization.
Render efficiency.
23
VIEW LAYER CONNECTIONS
View
View Model
Data display
View
View Model
Alternate layout
View
View Model
Tab like interface
View
View Model
View Model
24
VIEW TESTING
View
Test ViewModel ViewModel
Model
AppAcceptance testing
Mock View Model
Unit testing
25
TDD IN VIEW: CELL TAP
Setup expectation for correct call
Verify call correctness
Fire expectation Is Equal to string wrapper34
TDD IN VIEW: CELL TAPSend event to cell
Push segue require NavConWait for UIKit internalsSend event
Verify
36
VIEWMODEL LAYER
WD40 for your data.
Intermediate view context.
Umbrella for interfaces.
Thin (5-15 % of code)
38
VIEW MODEL TESTING
TDD
As simple as possible.
Model state changes — ViewModel state changes
ViewModel receive call — Model receive call
Can hold more than one model.
40
CORE
Fail = Crash
Minimum frameworks. (Core Data instances may be exceptions)
Do not owns a facades.
Owns services.
Data consistence.
44
WHAT ABOUT BINDINGS?
Any bindings is implementation detail.
Cross layer usage.
At least cross object.
47
APPLE PUSH OPTIONS
SOURCE: DESTINATION:
set @property Setter
Call method Method
Source is depend on Destination.
Abstract layer depend on Concrete51
APPLE PULL OPTIONS
SOURCE: DESTINATION:
KVO
KVO
- observe…
NSNotification @selector()
String based typing.
Runtime error detection.
Threads and ownership53
RAC OPTIONS:
SOURCE: DESTINATION:
@property …
RAC(…) = …
rac_liftSelector:
RACSignal* …
RAC(…) = …
54
RAC USING: NO LOGIC INSIDE
Do not mix with UIKit
Do not mix with Networking
Do not mix with Layout
Do not mix with CoreData
Do not mix with Threading
58
LINKS
http://cocoasamurai.blogspot.ca/2013/03/basic-mvvm-with-reactivecocoa.html
https://speakerdeck.com/jspahrsummers/code-reuse-with-mvvm
https://speakerdeck.com/dalog/m-v-vm-basics
http://componentkit.org/
http://jlongster.com/Removing-User-Interface-Complexity,-or-Why-React-is-Awesome