Skip to content
This repository was archived by the owner on Jan 30, 2021. It is now read-only.

Comments

Coordinator Cleanup#75

Open
heyltsjay wants to merge 6 commits intomasterfrom
feature/heyltsjay/coordinatorCleanup
Open

Coordinator Cleanup#75
heyltsjay wants to merge 6 commits intomasterfrom
feature/heyltsjay/coordinatorCleanup

Conversation

@heyltsjay
Copy link

@heyltsjay heyltsjay commented Mar 21, 2018

A few things here:

  • Simplifies Coordinator down to class Coordinator: NSObject {}
  • Moves presentation style to be determined by parents
  • Adopts a pattern to attach to children so that Coordinator lifecycles are ultimately determined by the View/Navigation hierarchy. This reduces the need to hold any reference to children and eliminates the need to hold strong references to children, which is now forbidden.
  • Removes some noise from the demo code to just demonstrate the pattern and little else.

Copy link

@jvisenti jvisenti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally like the ownership change, but am a bit fearful that since attach is required everywhere someone will forget it somewhere and cause a hard-to-track-down bug. Any way it can be more enforced?

- Manage view controller transitions
- Deinit when the views they manage Deinit
- `attach()` to the lifecycle of their children
- **NOT** hold strong references to their children

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#nth Add a should **NOT** hold strong references to coordinators somewhere in here. Just to contrast with how we used to always hold strong refs to make sure they didn't go away

window.setRootViewController(rootController, animated: false, completion: {
self.window.makeKeyAndVisible()
func start(with presentation: (UIViewController) -> Void) {
guard OnboardingCoordinator.hasOnboarded else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#pp Instead of guarding with early returns, use if/else. This bit me on a project where I wanted to do something after the correct coordinator was chosen, and had to do it with a defer.


class Coordinator: NSObject {}

extension Coordinator {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#pp I don't see why this would be in an extension instead of the class declaration body. Only thing I can think of is that you didn't want the methods to be overridable (since you can't override non @objc functions defined in an extension), in which case you could just mark them final. I personally would rather they be overridable incase a subclass wanted to do something additional when attached. Maybe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly in an extension to try to box up the code that deals with associated objects

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same file though. And has the side effect of limiting inheritance.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had originally toyed with a CoordinatorProtocol: class, NSObjectProtocol and Coordinator: NSObject, CoordinatorProtocol and was considering trying to expose in an extension on the protocol, but I waffled on if a protocol was valuable at all

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Attach/Detach behavior could technically just be an extension on AnyObject but that seems ripe for abuse

@chrisballinger
Copy link
Contributor

Is this something that should be revisited soon?

@heyltsjay
Copy link
Author

heyltsjay commented Apr 12, 2018

Hey @chrisballinger, Rob V and I are currently taking the pattern for a spin. We're curious if the attach pattern in combination with style rules (only holding weak references to children) will help iron out some common ownership issues that come from typical Coordinator/Controller patterns.

@heyltsjay
Copy link
Author

Seems a little too opinionated to merge into the template before someone gets some insight by using it in a client project. Open to feedback!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants