Friday, January 10, 2014

NIB-Based Xcode iOS Template

I once failed one of those coding test job interviews things because of the changes made while I wasn't looking to Xcode templates. In my defence I hadn't actually needed to create a new project in a while and we'd just moved to a new version of Xcode and so on. The challenge itself wasn't too hard — just grab an XML file from a server, parse it, and then display the results in a table — but by the time I'd beaten the empty project into a shape I recognised most of the time had already slipped away. Ce la vie.

More recently, Xcode has moved to having all new templates use Storyboards by default. Often, this isn't what you want. While there are ways of reverting to the NIB-based templates available in Xcode 4, they aren't quite as simple as all that. Which is why I made this basic NIB-based template, which you can grab from GitHub here. Full installation instructions ("drop it into a folder") are included.

This template isn't a direct clone of the old-style ones, since by default it creates the application window and root view controller in code rather than loading them from a main NIB. What it does do is to create a NIB (or two NIBs, in the case of universal apps) for the root UIViewController subclass. I think this is close enough to the old behaviour for the usual use case of needing a quick test bed for trying something out — for any more substantial projects you're going to want to take the time to configure them by hand anyway. The template inherits (as far as Xcode templates implement inheritance) from Xcode's default iOS template, which means that projects created from it in the future will benefit from whatever (hopefully sane) changes Apple make there.

I was helped to throw this together by this StackOverflow post, and this description of the template format which it linked to.

No comments: