Pitfalls with XIB Deployment Target

Published on October 1, 2010

I encountered a bug when installing my app on a device running iOS 3.x. The app runs fine with iOS 4.x, but crashed on iOS 3.x.

The error message is an NSUnknownKeyException encountered when the application main is run.

Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[<UIWindow 0x1451d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key rootViewController.’

After some digging, I found that it is to do with my Deployment Target of my MainWindow.xib file being set to iOS 4, when it should really be All Versions of iOS.

This happened when the project is created, and then I changed to Project’s Deployment Target to iOS 3.0. Although the project’s specified iOS 3.0, all xib files will not automatically change its deployment target.

This is what I see when I change the deployment target to All Versions of iOS.

Xib Document Info]

(To change xib info, in Interface Builder, go to Windows > Document Info)

What is good here is that once I changed to All Versions of iOS, Interface Builder will warn me of the issues. As it says, UIWindow does not have a rootViewController prior to iOS 4.0! Who knows that!?