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
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
Azure SRE Agentで運用は楽になるのか?
kkamegawa
0
2.2k
Introducing ReActionView: A new ActionView-compatible ERB Engine @ Rails World 2025, Amsterdam
marcoroth
0
690
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
390
Oracle Database Technology Night 92 Database Connection control FAN-AC
oracle4engineer
PRO
1
440
個人軟體時代
ethanhuang13
0
320
詳解!defer panic recover のしくみ / Understanding defer, panic, and recover
convto
0
240
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
4
1.4k
2025 年のコーディングエージェントの現在地とエンジニアの仕事の変化について
azukiazusa1
24
12k
Laravel Boost 超入門
fire_arlo
3
210
AIコーディングAgentとの向き合い方
eycjur
0
270
Kiroで始めるAI-DLC
kaonash
2
590
もうちょっといいRubyプロファイラを作りたい (2025)
osyoyu
1
430
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
A Tale of Four Properties
chriscoyier
160
23k
How to train your dragon (web standard)
notwaldorf
96
6.2k
Bash Introduction
62gerente
615
210k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Practical Orchestrator
shlominoach
190
11k
Facilitating Awesome Meetings
lara
55
6.5k
Testing 201, or: Great Expectations
jmmastey
45
7.7k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
GitHub's CSS Performance
jonrohan
1032
460k
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