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
Yoshikuni Kato
March 22, 2017
Programming
3
2.3k
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
The Elm Architecture & Swift
yoching
0
880
iOS developers community in Tokyo
yoching
0
640
Swiftエンジニアが海外のポジションに応募する
yoching
10
2.9k
App Architecture By Manual DI
yoching
0
640
Passing function to function arguments
yoching
0
610
「新規アプリの設計」を設計する
yoching
1
1.8k
App Architecture By Manual DI
yoching
2
520
関数を引数として渡す書き方のポイント
yoching
0
750
App Architecture Sample
yoching
0
92
Other Decks in Programming
See All in Programming
最新TCAキャッチアップ
0si43
0
140
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
150
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Remix on Hono on Cloudflare Workers
yusukebe
1
280
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
1
110
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
43
13k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Automating Front-end Workflow
addyosmani
1366
200k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
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