The new UISplitViewController and iOS 7

Splitting all the things

tl;dr download the sample project

iOS 8 updated the UISplitViewController API to work on iPhones. It let's you specify when and how the split layout happens.

You end up with a universal storyboard which is very DRY.

However, I assumed that the new UISplitViewController only worked for iPhones running at least iOS 8.

Problem is that the iOS 8 adoption rate is really bad compared to previous versions. As of November 17, 2014 iOS 8 still has less than 60% of the market.

I thought that in order to use UISplitViewController I would have to scatter my code with OS if-statements or use multiple storyboards.

But it turns out that the new UISplitViewController APIs are fully compatible with iOS 7! Why Apple doesn't document this out is beyond me.

Yup, you can use a single storyboard with a UISplitViewController and have all of this without any compatibility checking:

There are probably even more customizations, these are just the ones that I've been playing with.

Getting it to work

This NSHipster article got me rolling with UISplitViewController. Using their pattern, you need:

Use a Show (Detail) segue from your table cell to the detail navigation controller.

Interface Builder

In -prepareForSegue: of the master controller, you will need to check if the segue destination is either a UINavigationController (from a split view detail swap) or your detail controller (from a nav push).

var dest: DetailController
if let nav = segue.destinationViewController as? UINavigationController {
  dest = nav.topViewController as DetailController
} else {
  dest = segue.destinationViewController as DetailController
}

Finally, whatever is the delegate for your UISplitViewController needs to implement this long-ass delegate method:

func splitViewController(
  splitViewController: UISplitViewController,
  collapseSecondaryViewController secondaryViewController: UIViewController!,
  ontoPrimaryViewController primaryViewController: UIViewController!) -> Bool
{
  return true
}

Check out the sample project on Github and try it for yourself. This project has been tested on iOS 7 on all simulators and an iPhone 4 as well as iOS 8 on an iPhone 6 and all simulators.