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
Charles-Henri DUMALIN
April 19, 2018
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Coordinators and memory management
A talk given at Cocoaheads Lille in April 2018.
Charles-Henri DUMALIN
April 19, 2018
Other Decks in Programming
See All in Programming
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
250
Contextとはなにか
chiroruxx
1
390
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
240
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
320
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.8k
Webフレームワークの ベンチマークについて
yusukebe
0
200
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
1
470
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
220
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
460
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
240
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
170
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Into the Great Unknown - MozCon
thekraken
41
2.6k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
450
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.2k
Paper Plane (Part 1)
katiecoart
PRO
0
9.5k
Making the Leap to Tech Lead
cromwellryan
135
10k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.9k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
220
The World Runs on Bad Software
bkeepers
PRO
72
12k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
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