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

Flow Controllers

Flow Controllers

Presentation in french I gave on Flow Controllers at a Paris Swift Meetup.

Ali Karagoz

May 18, 2016
Tweet

Other Decks in Programming

Transcript

  1. LES PROBLÈMES AVEC LES VIEW CONTROLLERS ! TROP DE RESPONSABILITÉS

    > fort couplage & faible réutilisabilité ! > difficile à tester ! > massif "
  2. PRATIQUE COURANTE @IBAction func didTapShareButton() { let shareViewController = ShareViewController()

    if Env.IsIPad { shareViewController.modalPresentationStyle = .FormSheet self.presentViewController(shareViewController, animated: true, completion: nil) } else { self.navigationController?.pushViewController(shareViewController, animated: true) } }
  3. In real life, children should never tell their parents what

    to do. In programming, I would argue children shouldn’t even know who their parents are! — Soroush Khanlou
  4. In real life, children should never tell their parents what

    to do. In programming, I would argue children shouldn’t even know who their parents are! — Ali Karagoz
  5. WHAT IS A FLOW CONTROLLER C'est un objet qui manage

    des view controllers et qui est responsable de leur instanciation, presentation et disparition
  6. FLOW CONTROLLERS EN PRATIQUE > manage le navigation flow de

    l'application > gère un ou plusieurs view controllers > peut avoir des flow controllers enfant ! > manipule la data
  7. SANS FLOW CONTROLLER chaque view controller connait sa position dans

    le navigation flow et sait instancier le view controller suivant
  8. class FlowController { /// Usually initialized with a `UINavigationControlller`, but

    not only init(navigationController navigationController: UINavigationController) { self.navigationController = navigationController super.init() } }
  9. class ViewController: UIViewController { } /// `ViewController` has a delegate

    to "talk" to the outside protocol ViewControllerDelegate { func didTapButton(viewController: ViewController) }
  10. /// The flow controller implements the delegate and is reponsible

    of the flow extension FlowController: ViewControllerDelegate { func didTapButton(viewController: ViewController) { let otherViewController = OtherViewController() otherViewController.delegate = self self.navigationController?.pushViewController(otherNavigationController, animated: false) } }
  11. class FlowController { init(navigationController navigationController: UINavigationController) { self.navigationController = navigationController

    super.init() } /// `start()` is just here to make setup the root view controller and eventually decide which /// child flow controller should be instantiated. func start() { let viewController = ViewController() viewController.delegate = self self.navigationController.viewControllers = [viewController] } }
  12. FLOW CONTROLLERS EN BREF > moins de responsabilités ! >

    plus d'isolation & réutilisabilité élevée ! > encapsulation des tâches ! > navigation flow clair !
  13. LINKS > Coordinators Redux - Soroush Khanlou > Improve your

    iOS Architecture with FlowControllers - Krzysztof Zabłocki > Coordinators with Storyboards - Warren Gavin > Flow Controllers on iOS for a Better Navigation Control - Alberto De Bortoli