Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Coordinatorパターンの実践

 Coordinatorパターンの実践

Yoshikuni Kato

March 22, 2017
Tweet

More Decks by Yoshikuni Kato

Other Decks in Programming

Transcript

  1. Who am I? • Ճ౻༝܇ʢYoshikuni Katoʣ @yoshikuni_kato • iOSΤϯδχΞ •

    Yahoo! Japan -> Φϋί • ʮϥδ΁͐ʯ͘Μ → • Interests: ઃܭ / FRP / Coordinator PaCern / UI࣮૷ 2
  2. 5

  3. 6

  4. Naviga&onCoordinator protocol protocol NavigationCoordinator: Coordinator { var navigationController: UINavigationController {

    get } } extension NavigationCoordinator { var presenter: UIViewController { return navigationController as UIViewController } } 9
  5. TabBarCoordinator protocol protocol TabBarCoordinator: Coordinator { var tabBarController: UITabBarController {

    get } } extension TabBarCoordinator { var presenter: UIViewController { return tabBarController as UIViewController } } 10
  6. 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
  7. 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
  8. 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
  9. 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
  10. ࢀߟ • ը໘ભҠͷ؅ཧͱ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