I'm working on an application utilizing the Coordinator and MVVM patterns.
The coordinator protocol looks as follows:
protocol Coordinator: class {
func start()
func start(with deeplink: DeeplinkOption?)
}
The start method has the logic to start the current coordinator flow, e.g. create the corresponding initial view controller, view model, etc.
I've tried adding deeplink handling to the Coordinator protocol via the start(with deeplink: DeeplinkOption?) method. The issue is that I need to pass the deeplink data to an already existing view model in a specific coordinator and that coordinator doesn't hold the reference to the target view model. For example imagine the following stack:
appCoordinator
chat coordinator
- chat screen
- user details screen
The user is currently on the user details screen, and I need to pass the deeplink action to the chat screen view model. There's also no reason to re-create the chat screen from scratch as it's done in the start method since the chat screen is already in the navigation stack.
Is there a neat solution for this issue (and coordinator pattern overall) without storing the reference to a corresponding view model?