Xcode 7 Storyboard References (Beta 1)

101 1

Xcode 7 has some great new features one of those is handling busy storyboards that often occur with big or complicated applications. Now you have the ability to move related views to a separate storyboard file and reference that storyboard as needed. This allows you to group similar content giving a clearer picture, lets take a look at how it works.

There is also a video version of this tutorial available

 

Combine several storyboards into a separate file

  1. Select some connected storyboards

Main.storyboard — Selected ViewControllers  

  1. Go to the menu and choose Editor > Refactor to Storyboard

  2. Enter a new file name for the storyboard

  3. Selected storyboards are removed from the original storyboard and put in the new file

NewBoards Grouped

  1. The original storyboard now has a storyboard reference to the new file

Main storyboard with reference

Note that you can either open the storyboard file to edit the contents or you can double click on the reference created in the main storyboard to open the file.

Now let’s take a look at a way to link from our new storyboard back to the main one.  

Creating a link to another storyboard

  1. Drag the Storyboard Reference object from the library to the open storyboard

NewBoard with reference object

  1. Create a button on viewController and right click drag to the Storyboard Reference

NewBoard with reference and button

  1. In the Storyboard Reference attributes inspector select the storyboard you want to link to in the Storyboard dropdown i.e. ‘Main’

NewBoard with reference and attributes inspector main selected

Other entries you can put in the attributes are  

Reference ID

  This gives you the option to enter a controller name, if you leave it empty then by default it will use the controller specified in the storyboard configuration.  

Bundle

  If you have your storyboard in a separate framework then you specify that name here so the compiler knows where to find the referenced storyboard. Again, leaving it blank defaults to the default bundle assuming the storyboards are in the same bundle.   So I think you can see that this new feature might seem minor at first but can become a big time and productivity saver when you have a lot of layouts to manage.   Another thing to consider is the linking to a bundle, this means you can easily have your own framework of standard screens and just link to them giving consistency and easy updating across a range of applications.