WWDC24 SALE: Save 50% on all my Swift books and bundles! >>

How to use storyboard references to simplify your storyboards

Swift version: 5.10

Paul Hudson    @twostraws   

Storyboards deliver useful features, such as being able to see a lot of your user interface side-by-side and being able to design static cell designs for your table and collection views. However, they can also cause havoc with teams, because two developers attempting to modify the storyboard at the same time will immediately hit source control problems.

Fortunately, Interface Builder comes with a simple solution in the form of storyboard references: links that connect one storyboard to another, using any identifier or presentation segue you want. They let you break up one huge storyboard into several smaller ones, and in doing so also allow you to re-use scenes more easily.

Storyboard references are easy to use, but don’t get a lot of use because they were introduced four years(!) after storyboards – a lot of folks either decided they didn’t like the initial storyboard implementation and haven’t checked back since, or still use the same approach they learned back in iOS 5.

Using storyboard references takes three steps:

  1. Create a new storyboard in your app, e.g. Subscribe.storyboard. Inside there create a view controller however you need, and give it a storyboard identifier.
  2. In Main.storyboard, drag out a storyboard reference object. In the attributes inspector select your new storyboard from the Storyboard dropdown, then enter your target storyboard identifier in the Referenced ID box.
  3. That storyboard reference can now be treated like a regular view controller, so you can make connections to it such as a Show segue.

Xcode will check your configuration at build time, so if you try to reference a storyboard identifier that doesn’t exist your project will refuse to build.

While storyboard references do solve the problem of storyboards becoming unwieldy and tricky with source control, they don’t solve the problem of storyboards forcing your app to flow in a certain direction. For that you should consider something like the coordinator pattern instead.

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Available from iOS 9.0

Similar solutions…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

Average rating: 3.7/5

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.