How to build apps for iOS 5 with Xcode 5.1

Ios-5.1-640x480Recently I get the feeling that iOS 5 is an indiscretion Apple would rather forget. Never mind that the iPad 1 is still around and really not a bad device. Besides, iOS 5 paved the way for iCloud.

I like to support iOS 5 if I can – but with the latest Xcode 5.1 release it’s getting tougher. It is still possible, even though we no longer have access to the iOS 5 simulator. But with a real device attached you can still support and debug apps on iOS 5.

I’ve picked up a few tips and tricks – and here’s what you can do with Xcode 5.1 to make apps run on again under iOS 5:

Change the Deployment Target

Notice that Xcode no longer brings up iOS 5 from the deployment target menu. No problem, just type in what you want. Choose 5.1.1 (manually) to support both 64 and 32 bit binaries – no need to change the default build architecture this way.

Screen Shot 2014-04-04 at 11.58.18


The next big issue you’ll face are storyboards. Introduced in iOS 5, they seemingly no longer work when deployed from Xcode 5.1. There are two problems here.

One of them is Auto Layout. iOS 5 doesn’t understand it, I personally hate it – and I’m happy to say it’s easy to switch off. Select your storyboard, check out the file inspector and just untick the Auto Layout Box:

Screen Shot 2014-04-04 at 12.03.11

But even without Auto Layout, iOS 5 still won’t run an app with such a storyboard and will instead crash when deployed. The error message is something like “Could not find a storyboard named ‘Main’ in Bundle”.

Let’s fix that next.

At first this looks like a problem with an unlinked file, as if the storyboard is not added to the bundle at compile time. And sure enough, if you head over to Build Phases – Compile Sources, you don’t see your storyboard added here, as you once did:

Screen Shot 2014-04-04 at 12.13.52

The reason for this is the way Xcode now handles translations. Back in the day you had a single storyboard file, and if you wanted to translate it there was a lot of confusion in regards to base translations. You had to add those manually, then add an “English” version – it was messy.

Back then you needed a different storyboard file for every language, but since iOS 6 this was replaced with an easier system to manage: a single storyboard file, and additional strings files which would only contain the words that needed to be replaced (rather than all the XML data and positions for your elements). The previous system made it a tad cumbersome because moving a single button five pixels to the left isn’t easy when you have to do it across every language you supported.

But if you don’t care about translations, or you’re happy to do the extra work per storyboard, then here’s how to make the setup iOS 5 compatible again:

If you look at your storyboard in the file inspector (the previous screenshot), you’ll notice that you have “Base” and “English” as a localizable strings file under Translations. In fact, Xcode even compiles with a warning that “Internationlization is not available when compiling for targets before iOS 6.0”.

Simply untick “Base” and Xcode will present you with a dialogue box explaining that you’re now merging the English strings file into a storyboard file. Agree to it and your app will run fine on iOS 5 devices.

Screen Shot 2014-04-04 at 12.21.11

Core Data Model Files

The last big hurdle we may face is the way Xcode now creates Core Data Model files. Xcode may give an error such as “there was no MOMD file, or the file is nil” (in its own colourful words).

Here’s why: Back in iOS 5 days a .xcdatamodel file was a single file, turned into a .momd file at compile time. If you wanted to add a new version, this file would be put into a Bundle or Package, containing additional versions, as well as an XML file.

With Xcode 5 you get this package even if you only have a single model version – noticeable by the ending of your file .xcdatamodeld (the d at the end gives it away).

The solution here is to show the file in Finder, right-click on it and select “show package contents”. You’ll see your old favourite .xcdatamodel file (without the d at the end). Copy it to your Desktop, then drag it into Xcode (or choose “Add Files To Project”). Build again and the error message is gone!

Note that this problem may or may not happen in your Core Data project – I’ve had a 50% failure rate here.


The iOS 5 Simulator

You may have heard the shocking news: the iOS 5 simulator is no longer welcome on Mac OSX 10.9.x Mavericks. I believe it has to do with the kernel which is incompatible with some routines that used to power it.

But… if you still have access to Mountain Lion 10.8.x you’re in luck: Xcode 5.0 still has the iOS 5 simulator as a download, even though you can no longer deploy apps from Xcode to this version. With a small hack though we CAN still run an app on it, just to see if it works.

This approach is no good for debugging though because you don’t receive error messages in Xcode. But for completion I thought I’d mention how to at least test your app on the simulator this way.

Try this: deploy your iOS 5 compatible app on the iOS 6 simulator. Stop it in Xcode. Then back in the simulator, head over to Hardware – Device – pick a model – pick an iOS Version. Behold: you can still select iOS 5.1.

Do that and the simulator will switch. Check it out on the device in Settings – General – About:

Screen Shot 2014-04-04 at 13.00.19

Tears of joy! Now copy your deployed app manually to the iOS 5 simulator: Open a Finder Window and head over to Library/Application Support/iPhone Simulator/iOS6.1/Applications and find your app in there. It’s a cryptic folder name. Copy the entire folder over to the Applications folder in your iOS 5.1 directory.

Restart the simulator and find your app deployed and ready to rock.

Long live iOS 5 (before iOS 8 will make it impossible for us).

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

6 thoughts on “How to build apps for iOS 5 with Xcode 5.1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.