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
2.8k
3
Share
Coordinatorパターンの実践
potatotips #38
SampleCode:
https://github.com/yoching/CoordinatorSample
Yoshikuni Kato
March 22, 2017
More Decks by Yoshikuni Kato
See All by Yoshikuni Kato
Fun of writing Unison
yoching
0
580
The Elm Architecture & Swift
yoching
0
1.3k
iOS developers community in Tokyo
yoching
0
920
Swiftエンジニアが海外のポジションに応募する
yoching
10
3.3k
App Architecture By Manual DI
yoching
0
890
Passing function to function arguments
yoching
0
920
「新規アプリの設計」を設計する
yoching
1
2.1k
App Architecture By Manual DI
yoching
2
620
関数を引数として渡す書き方のポイント
yoching
0
870
Other Decks in Programming
See All in Programming
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
480
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
170
PHPでバイナリをパースして理解するASN.1
muno92
PRO
0
430
Firefoxにコントリビューションして得られた学び
ken7253
2
160
AWSはOSSをどのように 考えているのか?
akihisaikeda
0
100
AIを導入する前にやるべきこと
negima
2
340
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
180
t *testing.T は どこからやってくるの?
otakakot
1
920
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
[RubyKaigi 2026] Require Hooks
palkan
1
310
2026年のソフトウェア開発を考える(2026/05版) / Software Engineering Scrum Fest Niigata 2026 Edition
twada
PRO
22
12k
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
200
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
0
340
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
280
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
170
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
180
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
690
The Invisible Side of Design
smashingmag
302
52k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
Designing for Performance
lara
611
70k
A designer walks into a library…
pauljervisheath
211
24k
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