Conversation
jvisenti
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
#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 { |
There was a problem hiding this comment.
#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 { |
There was a problem hiding this comment.
#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.
There was a problem hiding this comment.
It's mostly in an extension to try to box up the code that deals with associated objects
There was a problem hiding this comment.
In the same file though. And has the side effect of limiting inheritance.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
The Attach/Detach behavior could technically just be an extension on AnyObject but that seems ripe for abuse
|
Is this something that should be revisited soon? |
|
Hey @chrisballinger, Rob V and I are currently taking the pattern for a spin. We're curious if the |
|
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! |
A few things here:
class Coordinator: NSObject {}attachto 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.