How to share data between Navigation Controllers

The Root Navigation Controller can serve as a data model. Each View Controller connected to the Navigation Controller via push segue can access its properties like so:

Here’s an example. MyNavController is the class for the Navigation Controller. This snipped is called from any View Controller in sequence and assumes we have an integer myNumber which is increased by one:

The same principle works for Tab Bar Controllers too.

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!