With iOS 5 gaining traction, most of you have already moved to iOS 5+ in your apps. This means, you would have explored UIStoryboard and might have migrated some parts of the User Interface from nib files to Storyboards.

The problem

Storyboards have a rather annoying problem when you work as a team. When you create a new application (choosing the “Use Storyboards” option), Xcode creates a project with one Storyboard for the entire app. So any UI change made my two different developers at the same time could potentially end up in a merge conflict hell. Since Storyboards are internally auto-generated XML, these merge conflicts are too complicated (and almost impossible) to fix.

The Fix

Just because Xcode’s default template creates one Storyboard per project doesn’t mean you should cram all your UI into that. You can have multiple Storyboards in your project.

The fix I recommend for this is to break your application’s UI into multiple storyboard files, maintaining one file for every use case. In most cases, one developer would be working on a use case and chances of ending up with a merge conflict are lower.

Example 1

An example use case based storyboards for a Twitter client would be Login.Storyboard, Tweets.Storyboard, Settings.Storyboard and Profile.Storyboard.
Login.Storyboard would show the landing view, login view and/or register view.
Tweets.Storyboard would contain the tweets list view, mentions view, search tweets view, tweet details view, a web view for displaying links, a image view for displaying embedded images and a map view for showing location.
Settings.Storyboard would contain the settings and detailed options for settings like Instapaper login UI, choosing the URL shortener and similar stuff.
Profile.Storyboard would contain the user’s profile details view, friends list view etc.,

A developer who is working on the Login use case will probably not be working on Tweets. So, instead of breaking up into multiple XIBs (going back to square 1), using multiple Storyboards will help solve the merge conflict issue while preserving the elegance of using them.

Example 2

If your application is a UITabBarController based application or a sliding menu based application (like Path/Facebook), or a springboard menu driven application (LinkedIn) you can create one Storyboard file per menu option. So a Facebook like application would have a “Events.storyboard”, a “NewsFeed.storyboard”, a “Profile.storyboard” and so on.

I have been using this technique for quite a while and I would highly recommend that you use it too.

Mugunth

Follow me on Twitter

  • Can you segue between Storyboards in IB or does it require code?

    • MugunthKumar

      You cannot “segue” between view controllers in different storyboards. But that shouldn’t happen. You seldom segue from a settings view to a totally unrelated view like, say login or register. Right?

  • I avoid storyboards and XIBs.

    They don’t give enough value for the trouble.

    • MugunthKumar

      That’s almost like avoiding Xcode and using a makefile to build your product because Makefiles offer more control and granularity over Xcode project files.

      • Maybe but I’m not losing much productivity.

        BTW, I’m not using Xcode for daily my coding. Switched to AppCode.
        Using Xcode for testflight builds and AppStore builds.

  • agree with @MikaelBartlett:disqus They are not worth the risk/effort

  • KPM

    Do you have any example of how to link between those different storyboards? @twitter-5608452:disqus’s question is relevant. 

    • MugunthKumar

      Revert back to old style.

      UIViewController *controller = [[UIStoryboard storyboardWithNibName:@”blah”] instantiateViewControllerWithId:@”vcid”]; [self push/present: controller animated:YES];

  • Thanks for this post. I agree–I think Storyboards are useful but I can see the wisdom of using multiple storyboards for projects.

    If you are going to use multiple storyboards, how does memory management work?

    Does ARC automatically take care of eliminating the storyboard from the superview? (if it is in the superview at all?)

  • Guest

    Thanks for the info.
    Could you pls share a template for a UITabBarController based application?

    I’m curious to see how each tab is connected to it’s StoryBoard.