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

Gradual Coordinators

alper
May 16, 2018

Gradual Coordinators

alper

May 16, 2018
Tweet

More Decks by alper

Other Decks in Programming

Transcript

  1. Presentation Modes • Navigation controller • Modal presentation (of navigation

    controller) • Tab presentation (of a navigation controller) • Interstitials • etc.
  2. Messy Exits self.dismiss(animated: true, completion: nil) if let mcvc =

    self.menuContainerViewController { let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main) let vc = storyboard.instantiateViewController(withIdentif ier: "HomeNavigationController") mcvc.centerViewController = vc }
  3. –Me again “There are no architectures. Every implementation of an

    architecture is a collection of patterns, some of which are specific to the architecture and some specific to the application.”
  4. Coordinators • “Coordinators Essential tutorial”, Andrey Panov • “An iOS

    Coordinator Pattern”, Will Townsend • “Coordinators Redux”, Soroush Khanlou • “Improve your iOS Architecture with FlowControllers”, Krzysztof Zabłocki
  5. Does not blend • Protocols • Routers • Factories •

    Double bookkeeping with children • Cognitive overload
  6. Step by Step 1. Create Delegate Method for each exit

    point of a View Controller 2. In Coordinator replace initial segue with own presentation in start() 3. In flow replace all calls to performSegue with delegate method call 4. In coordinator implement delegate method to go to the next step (remove/show/push)
  7. Delegate Method // CONTRACT @objc protocol SelectSubjectViewControllerDelegate { func selectedCategories(selectedVendors:

    [[String: AnyObject]], selectedSubjects: [Subject]) } // CONFORMING VIEW CONTROLLER @property (weak, nonatomic) id<SelectSubjectViewControllerDelegate> delegate;
  8. start() [self performSegueWithIdentifier:kAddContract sender:self]; // REPLACE WITH UIStoryboard *addContractStoryboard =

    [UIStoryboard storyboardWithName:@"AddContract" bundle:nil]; SelectSubjectViewController *ssvc = (SelectSubjectViewController *)[addContractStoryboard instantiateViewControllerWithIdentifier:@"SelectSubje ctViewController"]; ssvc.delegate = self; [self.navigationController pushViewController:ssvc animated:YES];
  9. performSegue swap // REPLACE [self performSegueWithIdentifier:kSegue sender:self]; // AND if

    ([segue.identifier isEqualToString:kSegue]) {} // WITH [self.delegate selectedCategoriesWithSelectedVendors:self.sele ctedVendors selectedSubjects:self.selectedSubjects];
  10. implement delegate extension VoldersTabBarController: SelectSubjectViewControllerDelegate { func selectedCategories(selectedVendors: [[String :

    AnyObject]], selectedSubjects: [Subject]) { let storyboard = UIStoryboard(name: "AddContract", bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: "SelectVendorViewController") if let selectVendorVC = vc as? SelectVendorViewController { selectVendorVC.selectedVendors = NSMutableArray(array: selectedVendors) selectVendorVC.subjects = selectedSubjects selectVendorVC.delegate = self } if let nvc = self.viewControllers?[2] as? UINavigationController { nvc.pushViewController(vc, animated: true) } } }
  11. Issues • Loss of locality (lots of code in different

    places) • Xcode does not like empty segues • Dual class UITabbarController subclass to be ad-hoc Coordinator • Not neatly composable • Navigation actions are a (fixable/irrelevant) issue