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
Coordinatorパターンの実践
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yoshikuni Kato
March 22, 2017
Programming
3
2.6k
Coordinatorパターンの実践
potatotips #38
SampleCode:
https://github.com/yoching/CoordinatorSample
Yoshikuni Kato
March 22, 2017
Tweet
Share
More Decks by Yoshikuni Kato
See All by Yoshikuni Kato
Fun of writing Unison
yoching
0
340
The Elm Architecture & Swift
yoching
0
1.1k
iOS developers community in Tokyo
yoching
0
790
Swiftエンジニアが海外のポジションに応募する
yoching
10
3.2k
App Architecture By Manual DI
yoching
0
760
Passing function to function arguments
yoching
0
780
「新規アプリの設計」を設計する
yoching
1
2k
App Architecture By Manual DI
yoching
2
610
関数を引数として渡す書き方のポイント
yoching
0
840
Other Decks in Programming
See All in Programming
Grafana:建立系統全知視角的捷徑
blueswen
0
320
AI 駆動開発ライフサイクル(AI-DLC):ソフトウェアエンジニアリングの再構築 / AI-DLC Introduction
kanamasa
12
6.4k
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
160
Oxlintはいいぞ
yug1224
5
1.3k
AgentCoreとHuman in the Loop
har1101
5
220
Patterns of Patterns
denyspoltorak
0
1.3k
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
140
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
110
CSC307 Lecture 02
javiergs
PRO
1
770
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
980
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
2
210
Exploring anti-patterns in Rails
aemeredith
2
250
Navigating Weather and Climate Data
rabernat
0
97
AI Search: Where Are We & What Can We Do About It?
aleyda
0
6.9k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
Practical Orchestrator
shlominoach
191
11k
Un-Boring Meetings
codingconduct
0
200
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
920
KATA
mclloyd
PRO
34
15k
Are puppies a ranking factor?
jonoalderson
1
2.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Transcript
Coordinatorύλʔϯͷ࣮ફ @yoshikuni_kato potato%ps #38 2017/03/22 1
Who am I? • Ճ౻༝܇ʢYoshikuni Katoʣ @yoshikuni_kato • iOSΤϯδχΞ •
Yahoo! Japan -> Φϋί • ʮϥδ͐ʯ͘Μ → • Interests: ઃܭ / FRP / Coordinator PaCern / UI࣮ 2
Agenda • Coordinatorύλʔϯͷ࣮ྫΛհ͍ͨ͠ • Coordinator: ը໘ભҠͷϩδοΫΛVC͔ΒΓग़ͨ͠ͷ • աڈͷࢿྉʢը໘ભҠͷཧͱMVVMʣΛࢀর͍ͩ͘͞ 3
ιʔείʔυ h"ps:/ /github.com/yoching/CoordinatorSample 4
5
6
Coordinatorͷ࡞୯Ґ • ʮதʹෳͷVCΛ࣋ͭVCʯ୯ҐͰCoordinatorΛ࡞Δͱ͔Γ ͍͢ • UINaviga0onController • UITabBarController • containerViewΛར༻͍ͯ͠ΔViewController
• UXతͳׂͱҰக͢Δͣ 7
Coordinator protocol protocol Coordinator { var presenter: UIViewController { get
} func start() } 8
Naviga&onCoordinator protocol protocol NavigationCoordinator: Coordinator { var navigationController: UINavigationController {
get } } extension NavigationCoordinator { var presenter: UIViewController { return navigationController as UIViewController } } 9
TabBarCoordinator protocol protocol TabBarCoordinator: Coordinator { var tabBarController: UITabBarController {
get } } extension TabBarCoordinator { var presenter: UIViewController { return tabBarController as UIViewController } } 10
AppCoordinator final class AppCoordinator { private let window: UIWindow private
let rootCoordinator: Coordinator init(window: UIWindow, rootCoordinator: Coordinator) { self.window = window self.rootCoordinator = rootCoordinator } func start() { rootCoordinator.start() window.rootViewController = rootCoordinator.presenter window.makeKeyAndVisible() } } 11
MainTabCoordinator final class MainTabCoordinator: TabBarCoordinator { let tabBarController: UITabBarController private
let childCoordinators: [Coordinator] init(presenter: UITabBarController, childCoordinators: [Coordinator]) { self.tabBarController = presenter self.childCoordinators = childCoordinators } func start() { childCoordinators.forEach { coordinator in coordinator.start() } tabBarController.setViewControllers( childCoordinators.map { $0.presenter }, animated: false ) } } 12
2ͭͷNaviga'onͰڞ௨͢ΔભҠ͕͋Δ • ભҠ ɹ→ protocol-orientedʹղܾ 13
DetailsPresentable protocol protocol DetailsPresentable { func showItemDetail(item: Item) func showUserDetail(user:
User) } 14
DetailsPresentable extension extension DetailsPresentable where Self: NavigationCoordinator { func showItemDetail(item:
Item) { let itemDetailVC = StoryboardScene.ItemDetailViewController.initialViewController() itemDetailVC.item = item itemDetailVC.userTapped = showUserDetail navigationController.pushViewController(itemDetailVC, animated: true) } func showUserDetail(user: User) { // ... } } ※ VC→Coordinatorͷ௨৴ɺclosureΛհ͢ / delegate / Observable(FRP) ͳͲ 15
FeedCoordinator final class FeedCoordinator: NavigationCoordinator, DetailsPresentable { let navigationController: UINavigationController
init(presenter: UINavigationController) { self.navigationController = presenter presenter.title = "Feed" } func start() { let feedViewController = StoryboardScene.FeedViewController.initialViewController() feedViewController.itemSelected = showItemDetail navigationController.pushViewController(feedViewController, animated: false) } } 16
Summary • Coordinatorͷ࡞ྫͷհ • h+ps:/ /github.com/yoching/CoordinatorSample • Ͳ͏ׂ͢Δ͔ • ڞ௨ॲཧΛprotocol-orientedʹղܾ͢Δ
17
Thank you! 18
ࢀߟ • ը໘ભҠͷཧͱMVVM • Presen)ng Coordinators by Soroush Khanlou, NSSpain(2015)
• Boundaries in Prac)ce by Nonaka Ayaka, try!SwiH(2016) • MVVM-C In Prac)ce by Steve ScoM, UIKonf(2016) • Connec)ng View Controllers at SwiH Talk(objc.io), 2016 19