Advanced iOS App Architecture
By René Cacheaux & Josh Berlin
Copyright ©2022 Razeware LLC.
Notice of Rights
All rights reserved. No part of this book or corresponding materials (such as text,
images, or source code) may be reproduced or distributed by any means without
prior written permission of the copyright owner.
Notice of Liability
This book and all corresponding materials (such as source code) are provided on an
“as is” basis, without warranty of any kind, express of implied, including but not
limited to the warranties of merchantability, fitness for a particular purpose, and
noninfringement. In no event shall the authors or copyright holders be liable for any
claim, damages or other liability, whether in action of contract, tort or otherwise,
arising from, out of or in connection with the software or the use of other dealing in
the software.
Trademarks
All trademarks and registered trademarks appearing in this book are the property of
their own respective owners.
Advanced iOS App Architecture Advanced iOS App Architecture
raywenderlich.com
2
Table of Contents: Overview
Book License 7................................................................................................
Before You Begin 8...................................................................
What You Need 9..........................................................................................
Book Source Code & Forums 11.............................................................
Section I 14.................................................................................
Chapter 1: Welcome 15..................................................................
Chapter 2: Which Architecture Is Right for Me? 18............
Chapter 3: Example App: Koober 38.........................................
Chapter 4: Objects & Their Dependencies 53.......................
Chapter 5: Architecture: MVVM 127.......................................
Chapter 6: Architecture: Redux 185.........................................
Chapter 7: Architecture: Elements, Part 1 239....................
Chapter 8: Architecture: Elements, Part 2 262....................
Conclusion 334..............................................................................................
Advanced iOS App Architecture
raywenderlich.com
3
Table of Contents: Extended
Book License 7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Before You Begin 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What You Need 9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Book Source Code & Forums 11. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
About the Authors 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
About the Editor 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Section I 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 1: Welcome 15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What lies ahead 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Who this book is for 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Where to go from here? 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 2: Which Architecture Is Right for Me? 18. . . . . . . . . . . . .
Identifying problems to solve 19. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Boosting team velocity and strengthening code quality 19. . . . . . . . . . . . . .
Examining the problems 22. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Increasing code agility 30. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Surveying architecture patterns 32. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Selecting a pattern 34. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Putting patterns into practice 36. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 37. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 3: Example App: Koober 38. . . . . . . . . . . . . . . . . . . . . . . . . . . .
Koober 38. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Why Koober? 46. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting started with the source 47. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 52. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 4: Objects & Their Dependencies 53. . . . . . . . . . . . . . . . . .
Advanced iOS App Architecture
raywenderlich.com
4
Establishing the goals 54. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Learning the lingo 55. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating dependencies 57. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The fundamental considerations 58. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Why is this architecture? 60. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dependency patterns 60. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dependency Injection 61. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
On-demand approach 67. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Factories approach 69. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Single-container approach 75. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Designing container hierarchies 78. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Applying DI theory to iOS apps 83. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Applying the on-demand approach 91. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Applying the factories approach 97. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Applying the single-container approach 110. . . . . . . . . . . . . . . . . . . . . . . . . . . .
Applying the container hierarchy approach 118. . . . . . . . . . . . . . . . . . . . . . . . .
Key points 125. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Where to go from here? 126. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 5: Architecture: MVVM 127. . . . . . . . . . . . . . . . . . . . . . . . . . .
What is it? 128. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Container views 134. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Communicating amongst view models 136. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Navigating 137. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Applying theory to iOS apps 141. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Composing views 152. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Navigating 163. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Managing state 176. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Pros and cons of MVVM 182. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 183. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Where to go from here? 184. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 6: Architecture: Redux 185. . . . . . . . . . . . . . . . . . . . . . . . . . . .
Advanced iOS App Architecture
raywenderlich.com
5