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
Coordinators and memory management
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Charles-Henri DUMALIN
April 19, 2018
Programming
0
130
Coordinators and memory management
A talk given at Cocoaheads Lille in April 2018.
Charles-Henri DUMALIN
April 19, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
「ブロックテーマでは再現できない」は本当か?
inc2734
0
970
dchart: charts from deck markup
ajstarks
3
990
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
650
Patterns of Patterns
denyspoltorak
0
1.4k
ThorVG Viewer In VS Code
nors
0
770
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.2k
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
190
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
120
CSC307 Lecture 05
javiergs
PRO
0
500
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
Featured
See All Featured
It's Worth the Effort
3n
188
29k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
49k
Why Our Code Smells
bkeepers
PRO
340
58k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
410
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
71k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
170
Six Lessons from altMBA
skipperchong
29
4.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
320
Transcript
Coordinators and memory
We all have this ViewController → Layout → View State
management → Data fetching & persistance → Navigation
Why is this? → ViewController have an unclear role in
UIKit → Apple's vision of MVC is not matching our needs
What is MVC?
What are Apple's components of MVC?
Why does this not match our expectations? → Apple expects
us to do a local first app with CoreData → In this context their architecture makes perfect sense
MVVM to the rescue
MVVM to the rescue → The ViewController becomes just a
part of the view level
Remember our ViewController? → Layout: UIView → View State management:
UIViewController → Data fetching & persistance: ViewModel → Navigation: ????
None
EXAMPLE CASE
None
Introducing Coordinator
What does a Coordinator do? → Manages the navigation flow
→ Instanciates the controllers and injects dependencies
How does it do it? → It's a plain Swift
object → You do what you want with it → You just implement the Coordinator Protocol → You use delegation (or Reactive Programming) at the controller level
Anatomy of a Coordinator public protocol Coordinator { func start(animated:
Bool) }
class AppCoordinator { let window: UIWindow let navigationController: UINavigationController! let
homeController: HomeViewController! init(window: UIWindow) { self.window = window } } extension AppCoordinator: Coordinator { func start(animated: Bool) { homeController = HomeViewController.instanciateFromStoryboard() navigationController = UINavigationController(root: homeController) window.rootViewController = navigationController window.makeKeyAndVisible() } }
class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var coordinator:
Coordinator! func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ) -> Bool { let window = UIWindow(frame: UIScreen.main.bounds) coordinator = AppCoordinator(window: window) coordinator.start(animated: false) self.window = window } }
class DetailCoordinator { let navigationController: UINavigationController let detailController: DetailViewController init(_
navigationController: UINavigationController) { self.navigationController = navigationController } } extension DetailCoordinator: Coordinator { func start(animated: Bool) { let detailController = DetailViewController.instanciateFromStoryboard() navigationController.pushViewController(detailController, animated: animated) } }
class AppCoordinator { let window: UIWindow let navigationController: UINavigationController! let
homeController: HomeViewController! var childCoordinator: Coordinator? init(window: UIWindow) { self.window = window } } extension AppCoordinator: Coordinator { func start(animated: Bool) { homeController = HomeViewController.instanciateFromStoryboard() homeController.delegate = self navigationController = UINavigationController(root: homeController) window.rootViewController = navigationController window.makeKeyAndVisible() } } extension AppCoordinator: HomeControllerDelegate { func didTouchDetailButton() { let coordinator = DetailCoordinator(_ navigationController: navigationController) coordinator.start() childCoordinator = coordinator } }
Yay we did it!
None
Wait what?! Beware the zombie Coordinators and UIViewControllers
None
What's the problem here ? → UIKit creates a strong
reference → But Coordinator should own it... → UIKit decides when the view is released
Play fair with UIKit → Don't fight it, embrace it
→ UIKit will always be there
None
None
None
! How do I let the parent Coordinator know that
the Coordinator is not needed anymore?
None
The lifecycle probe → When the ViewController is deallocated it
sends a message to the Coordinator → The Coordinator sends a message to its parent to be released
SO MUCH WORK
Meet Yui Github: CallMeSH/Yui
Yui streamlines the process → Conform to the protocol →
Follow the guidelines → You're done !
DEMO Time
Thank You Github: CallMeSH/Yui Twitter: @CallMeSH LinkedIn: Charles-Henri DUMALIN