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.1k
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
770
iOS developers community in Tokyo
yoching
0
570
Swiftエンジニアが海外のポジションに応募する
yoching
9
2.7k
App Architecture By Manual DI
yoching
0
590
Passing function to function arguments
yoching
0
550
「新規アプリの設計」を設計する
yoching
1
1.7k
App Architecture By Manual DI
yoching
2
460
関数を引数として渡す書き方のポイント
yoching
0
700
App Architecture Sample
yoching
0
88
Other Decks in Programming
See All in Programming
Hanami and htmx
bkuhlmann
0
210
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
320
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
360
データアナリストが行うDatabricksを活用したETLの自動化事例
shinoa
0
270
ONE WEDGE_company_guide
1wedge_one
0
480
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
780
try!Swift Tokyo 2024 参加報告 LT
akidon0000
1
220
What We Can Learn From OSS
inouehi
0
420
ゆるい個人開発のススメ
kuroppe1819
10
990
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
200
Code Reviews
bkuhlmann
4
890
TCAとKMPを用いた新規動画配信アプリ 「ABEMA Live」の設計
tomu28
1
100
Featured
See All Featured
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
The Brand Is Dead. Long Live the Brand.
mthomps
49
29k
Rails Girls Zürich Keynote
gr2m
91
13k
GraphQLの誤解/rethinking-graphql
sonatard
50
9.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
2
3.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
116
18k
Making the Leap to Tech Lead
cromwellryan
124
8.5k
A Tale of Four Properties
chriscoyier
151
22k
Debugging Ruby Performance
tmm1
70
11k
Building a Modern Day E-commerce SEO Strategy
aleyda
17
6.4k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
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