All Together Now... Multiple Storyboards

TL;DR Got multiple iOS developers? Use multiple storyboards.

Highs and Lows

Working on significant projects means working with a large code base and a multi-person team. Multi-person teams are fabulous for so many reasons -- code reviews, someone to bounce ideas off of and your nerf gun ally.

However, one thing that is not fun about multi-person teams are source control conflicts. You finish a feature, got to merge/rebase and you get a conflict. Ugh!

We almost exclusively use Storyboards for our iOS projects. And, by now, we're pretty sure the rest of the world does too. Using a single storyboard file is traditionally how a lot of projects are done. This inevitably becomes the biggest source of conflicts.

Solution

The aha moment is realizing that you can use multiple storyboards in your project. A great approach is to maintain a separate storyboard for each large 'functional' area. How you define functional area is dependent upon your particular app -- but here is how it could look:

Code

Whenever you transition from one functional area to the next you need to access a viewController. You can then use the standard APIs to transition using the acquired viewController. The question is, without the use of segues what is the best way to get a hold of the viewControllers that live across storyboards?

Hrrmmmmm.

A solid approach is to do the following:

  1. Add class methods to the UIViewController and UIStoryboard classes that will provide access to each viewController and storyboard respectively.

  2. In InterfaceBuilder add a Storyboard ID to the viewController. (In the Storyboard make sure you have tapped on the View Controller and not the View otherwise you will only see a Restoration ID!)

  3. Use the storyboard.instantiateViewControllerWithIdentifier method to instantiate the desired viewController. I.e., add a class extension to UIViewController that provides type methods to access each viewController you need to. E.g.,

Simple, organized and a huge reduction in conflicts. Huzzah!

To the future!

Using multiple storyboards is great approach. The only thing you lose is the ability to declare your segue types and visually see all of your connections between viewControllers.

Xcode 7 is doing a solid and providing access to do segues across storyboards. That means, no more excuses for not using multiple storyboards!

Here is how it works.

In your Storyboard there is a new type of Object called a storyboard reference. You can drag this object into your storyboard and it will allow you to configure a reference to a different viewController in a different storyboard. You can then create a reference between an existing viewController and the new storyboard reference!

In the screenshot below you can see that a storyboard reference named, secondVC was created. This secondVC storyboard reference is configured to point to a storyboard named Second and a viewController in the Second storyboard named secondVC as configured in the Storybaord and Reference ID properties respectively. All that is left is to drag from the button, Tap Me, to the storyboard reference.

In fact, in Xcode 7 they are making it really simple to move to multiple storyboards. If you have a single storyboard you can refactor into multiple by tapping on a scene in your storyboard and then going to edit --> Refactor to Storyboard. Boom!