Coordinator Pattern (c. 23): How to pass data back to parent/ sibling coordinator

Hi all,

If I’m using the coordinator pattern as outlined in chapter 23 of the Design Patterns by Tutorials book, how do I go about passing data back through to a parent coordinator from a child coordinator?

Imagine a scenario in which the child coordinator takes care of some lower level preferences that needs to propagate back to the parent so that it could be passed down to an alternative sibling route – in my specific use case I have an App Coordinator that manages Onboarding- and Home Coordinators. During the Onboarding process the user is asked for their in-app upgrade preferences which needs to be passed to the sibling Home Coordinator, both of which are managed by the App Coordinator.

I’ve thought about passing a general purpose dictionary back through the dismissal process which can be part of the dismissal closures, but wasn’t able to make this work. Any suggestions on how to best handle this?

@jrg.developer Can you please help with this when you get a chance? Thank you - much appreciated! :]

You might consider making the parent coordinator act as the delegate for its child coordinators.

In such, it’s okay and appropriate for a parent to know about its concrete children. However, children should not know about their concrete parent or other sibling coordinators. These helps keep the design flex – you could reuse children between several parents, for example, by doing this.

In response to getting delegate callbacks from one child coordinator, the parent coordinator can setup or pass the info onto another child coordinator.

Make sense?

I hope this helps. Let me know if you have any other questions. :]

1 Like

Thank you @jrg.developer, that makes total sense!

I decided to edit the Coordinator dismissal closure to also pass back an optional data dictionary which can contain any arbitrary number of data related to the Coordinator flow, such as outcomes etc. The parent coordinator can then inspect this and retrieve any data it may want.