Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MVVM+RAC+TDD
Search
DAloG
April 04, 2015
Programming
0
250
MVVM+RAC+TDD
How to. For those who can.
DAloG
April 04, 2015
Tweet
Share
More Decks by DAloG
See All by DAloG
State normalization (RU)
dalog
0
160
Redux + MQTT
dalog
1
760
От задач к проблемам
dalog
1
230
Unlimited power of Data-Driven UI
dalog
4
610
Data-Driven View Controllers. Tips and Tricks
dalog
5
1.8k
2 years of Redux in iOS. Lessons learned
dalog
0
340
Why unidirectional architecture matter for iOS.
dalog
1
270
Mobile backend without REST
dalog
2
88
Self managed teams 101
dalog
0
130
Other Decks in Programming
See All in Programming
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
4
1.3k
[JAWS-UG横浜 #79] re:Invent 2024 の DB アップデートは Multi-Region!
maroon1st
1
140
CI改善もDatadogとともに
taumu
0
110
定理証明プラットフォーム lapisla.net
abap34
1
1.7k
チームリードになって変わったこと
isaka1022
0
190
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
490
Bedrock Agentsレスポンス解析によるAgentのOps
licux
2
720
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
4
370
[Fin-JAWS 第38回 ~re:Invent 2024 金融re:Cap~]FaultInjectionServiceアップデート@pre:Invent2024
shintaro_fukatsu
0
400
Kanzawa.rbのLT大会を支える技術の裏側を変更する Ruby on Rails + Litestream 編
muryoimpl
0
220
Flutter × Firebase Genkit で加速する生成 AI アプリ開発
coborinai
0
150
Featured
See All Featured
Being A Developer After 40
akosma
89
590k
Git: the NoSQL Database
bkeepers
PRO
427
64k
A better future with KSS
kneath
238
17k
4 Signs Your Business is Dying
shpigford
182
22k
Facilitating Awesome Meetings
lara
51
6.2k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Why Our Code Smells
bkeepers
PRO
335
57k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
Become a Pro
speakerdeck
PRO
26
5.1k
Done Done
chrislema
182
16k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Transcript
HOW TO: MVVM + RAC + TDD Note: All info
is subject to change. April 2015 1
ABOUT Alexey Demedeckiy iOS developer at Ciklum CSC CI Mentor
2
BACKGROUND B2B projects. Rich data flow. Rich UI. Animation driven
UI. 3
AGENDA Road to MVVM MVVM State of the union TDD
on UI? RAC? Outro 4
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
MVVM 2.0 11
ONE DIRECTION STATE FLOW Source Destination Data as @properties 12
NO HIDDEN CONNECTIONS Source Destination Data as @properties Call methods
Set values 13
ONE DIRECTION EVENT FLOW Source Destination (void)[source callMethod] 14
NO SIDE EFFECTS Source Destination (void)[source callMethod] Return values Call
methods 15
HOW TO ACHIEVE? Destination owns a Source. Destination calls a
Source. Destination look at Source state. Destination is derived from Source. 16
AT SCALE D1 S2 S1 D2 System strong link 17
MVVM View Model ViewModel UIKit state flow event and ownership
flow 18
AT SCALE No singletons. Context derived object graph. Lifecycle is
determined by (UI + BL) 19
MVVM AT SCALE View Model ViewModel UIKit App component Creation
20
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 App Acceptance testing
Mock View Model Unit testing 25
TDD IN VIEW: SETUP 26
TDD IN VIEW: SETUP ARC Safe creation Window for events
27
TDD IN VIEW: DEALLOC 28
TDD IN VIEW: DEALLOC Expect dealloc RAC Dealloc hook Check
dealloc ARC safe nil 29
TDD IN VIEW: RELOAD DATA 30
TDD IN VIEW: RELOAD DATA Flag HOOK on SUT method
Check Set flag 31
TDD IN VIEW: CELL TAP Load mock data to table
view 32
TDD IN VIEW: CELL TAP Setup expectation for correct call
33
TDD IN VIEW: CELL TAP Setup expectation for correct call
Verify call correctness Fire expectation Is Equal to string wrapper 34
TDD IN VIEW: CELL TAP Send event to cell 35
TDD IN VIEW: CELL TAP Send event to cell Push
segue require NavCon Wait for UIKit internals Send event Verify 36
TDD IN VIEW: P.S KIF for interacting. We need to
wait. Sometimes. Test Behavior not code. 37
VIEWMODEL LAYER WD40 for your data. Intermediate view context. Umbrella
for interfaces. Thin (5-15 % of code) 38
VIEWMODEL CONNECTIONS View Model Model View Model Model View Model
Model View Model Model Core 39
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
MODEL LAYER Core F1 F2 F3 VM1 VM2 VM3 S1
S2 S3 41
FACADES Holding temporary contexts. Thin API Join several Core APIs.
42
FACADES: EXAMPLES Create new appointment in calendar. Write email. Fail
possible action etc. 43
CORE Fail = Crash Minimum frameworks. (Core Data instances may
be exceptions) Do not owns a facades. Owns services. Data consistence. 44
SERVICES All system API All frameworks. Request / Response API.
No cross service communication. 45
MODEL: PS Can be simpler. Much simpler. 46
WHAT ABOUT BINDINGS? Any bindings is implementation detail. Cross layer
usage. At least cross object. 47
KINDS OF MESSAGES: FROM: TO: Data Data Call Call Data
48
BINDINGS AS REACTIONS SOURCE: DESTINATION: State State Action Broadcast State
49
APPLE PUSH OPTIONS SOURCE: DESTINATION: set @property Setter Call method
Method 50
APPLE PUSH OPTIONS SOURCE: DESTINATION: set @property Setter Call method
Method Source is depend on Destination. Abstract layer depend on Concrete 51
APPLE PULL OPTIONS SOURCE: DESTINATION: KVO KVO - observe… NSNotification
@selector() 52
APPLE PULL OPTIONS SOURCE: DESTINATION: KVO KVO - observe… NSNotification
@selector() String based typing. Runtime error detection. Threads and ownership 53
RAC OPTIONS: SOURCE: DESTINATION: @property … RAC(…) = … rac_liftSelector:
RACSignal* … RAC(…) = … 54
RAC USING 55
RAC USING: SUBSCRIBE NEXT Don’t 56
RAC USING: SUBSCRIBE NEXT rac_liftSelector RAC(…) Exception: -(RACSignal*)fn (limited context)
57
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
RAC USING: ABSTRACT TOOLS 59
RAC USING: ABSTRACT TOOLS 60
RAC USING: DECOMPOSE Fixing on instance Tech details Actual binding
61
RAC USING: DECOMPOSE 62
RAC USING: DECOMPOSE 63
RAC USING: DOUBLE WEAK 64
RAC USING: DOUBLE WEAK view not loaded yet first value
missed replay value 65
RAC: PS Just glue. Powerful. Dangerous. 66
FUTURE ComponentsKit (@Facebook) Swift Implicit binding
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
QUESTIONS email:
[email protected]
skype: nobidon THE END 69