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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Charles-Henri DUMALIN
April 19, 2018
Programming
130
0
Share
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
モダンOBSプラグイン開発
umireon
0
190
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
730
Mastering Event Sourcing: Your Parents Holidayed in Yugoslavia
super_marek
0
130
ファインチューニングせずメインコンペを解く方法
pokutuna
0
220
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
130
Claude Code Skill入門
mayahoney
0
450
PHPで TLSのプロトコルを実装してみる
higaki_program
0
610
Geminiをパートナーに神社DXシステムを個人開発した話(いなめぐDX 開発振り返り)
fujiba
0
130
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
130
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
260
今こそ押さえておきたい アマゾンウェブサービス(AWS)の データベースの基礎 おもクラ #6版
satoshi256kbyte
1
210
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
170
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
160
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The World Runs on Bad Software
bkeepers
PRO
72
12k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.5k
Color Theory Basics | Prateek | Gurzu
gurzu
0
270
30 Presentation Tips
portentint
PRO
1
260
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
240
Design in an AI World
tapps
0
190
Claude Code のすすめ
schroneko
67
220k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.4k
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