Xcode 4 problems

The time has come to upgrade to iOS 4.3 and Xcode 4.  Grrr.  The main problem I was having I could not find anywhere on google or in the dev forums, so I thought I should post my problem and fix here (after the jump) to hopefully help the next guy.

In general I suppose I resist change.  But for iOS app development I also sortof fear change because it means having to learn something new, and historically this is a time-suck of anywhere from a few nights to a week or so.  Of course Apple has to keep releasing new features, improving old features, adding capabilities, etc.  This is required to maintain their number one spot in the marketplace.  So, I get why it has to happen. But being a one man development shop, any time some new os is released it means I’m the only one to update everything to support the latest software.  What I fear the most is any new product release from apple.  Well, actually I’m torn on this because as an apple consumer /slash/ fanboy, I want new stuff.  But as a developer who has to support the new stuff, I fear it.  For example, if Apple were to add a retina display to the iPad and double the pixel resolution… it would throw me into a tailspin.  Supporting such a high resolution iPad would mean redoing a lot of my graphics.  I could skip it, but the key to success in the app store is being among the first to support the new features that Apple is pushing. So I’d have no choice but to dig in and do it as fast as possible.

Anyway, here I am a couple of days into trying to use Xcode 4 and iOS 4.3.  I’m not sure which of those two updates is causing the problems, but I’ve been battling it…

Actually I’ll skip all the details of installing, having some corrupted settings, having permissions issues, hard drive corruption, deciding to install a new root drive, and then reinstalling clean developer software.  I’ll skip all of that because that was likely a fluke.

No.. the problem I’m having is this:

2011-03-23 03:46:20.516 UICatalog[9809:207] *** Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason:
'Could not load NIB in bundle: 'NSBundle </Users/username/Library/
 Application Support/iPhone Simulator/4.3/Applications/67E625C1-
(loaded)' with name 'MainWindow''

This is happening mostly with older sample code that I have lying around.  But also with all my current apps, which were all originally developed back in the iOS 2.x – 3.x days. I’m still working through the issue, but I have been able to make the error go away with a couple of fixes.

First keep in mind that you can look in the path shown above to find the app package in the simulator’s Applications folder.  Show Package Contents and look to see if the missing file is in there.  That’s a good place to start.

Next is to make sure that in the info.plist for the app that you are not listing the .xib extension for the ‘Main nib base name’.  This means do this:

Main nib base name     MainWindow

instead of this:

Main nib base name     MainWindow.xib

The .xib gets compiled and turned into a .nib when placed in the bundle for the app.  So when I was listing the extension it might have been looking for MainWindow.xib.nib, and of course that file isn’t going to be there.  Also it’s not asking for the full name, only the base name.  Now that I think about it, I’m not sure if the .xib was there in my Xcode 3 project or not.  It’s possible that I added it when I tried removing and re-entering the plist entry.  Still I figure it’s worth mentioning.

The last thing, and probably the more likely problem has something to do with the version of Interface Builder the .xib was saved with.  There was something mentioned in the release notes about this, but it was written in code – not in regular guy english.  Since I’m still figuring all this out I experimented and found a solution inside of Xcode 4:  One by one select each .xib file and in the tab on the right under “Interface Builder Document” and make sure your deployment is set to “Project SDK”.

Then recompile and hopefully you’ll be golden.

UPDATE: Not So Fast…

Even after doing all this I still had some crashing issues.  I looked in the app bundle, which as I said above can be found in the folder specified in the error log, and there were all the .xib files but no .nib files.  And all the .xib files were in an english subfolder.  Back in my project folder (on the hard drive not in xcode) I moved them out.  This caused xcode to squawk!  Probably should have done it with the project closed.  Still I got past all the warnings and then re-added all of these files to the project and deleted all the old ones.

I’m not sure which of the things actually fixed the issue.  It could have been moving the files out of a subfolder in Resources.  OR it could have been the fact that the .xib files were removed and re-added to the project in xcode.  Either way it’s working now.  At least it gives you a few things to try if you run in to the issue.

UPDATE #2: Remove and Re-add is the trick

It happened on another project.  I’m glad I wrote this blog post cause it helped me figure it out in a few minutes instead of a few hours.  This time it turned out to be removing and re-adding the xibs in the project.  They were already in the root folder of the project (in finder), I moved them to the root of the project (in xcode), they were also already set as Project SDK version, and I upgraded their Development setting to IB3.2.  But to get it to work I had to deleted them from the project (in xcode), selected to only remove references, then dragged them back in from the finder, recompiled and all is golden now.

9 thoughts on “Xcode 4 problems

  1. Thank you so much !
    I had the same error. The weird thing was I only had the error when I wanted to build my project on an iPod Touch or iPad. In the simulator and on my iPhone everything just worked fine. I removed the .xib files from xcode and from the project folder and put them back in. Perfect 🙂

  2. Pingback: XCode 4 – Migrating the Penguins - OOgtech.org

  3. Worked for me too! Thanks a lot, man – thanks for posting your experience with that – it’s really cool that you found the time to help others.

    Anyway, I tried re-saving the xib files before I re-added them to the project and it had some effect. After re-saving MainWindow, the app kept crashing, but with an exception in a different xib file. However re-saving that xib didn’t now work. So I guess the real problem is indeed with the format of these files.

    Well, it’s not the first time a good re-adding of files in the xcode project did the trick, is it? 🙂

  4. Hi and Thanks.
    I had the same error.
    I’ve got it to run with delete all of the localization from the MainWindow.xib

  5. I’ve got the error in:

    RedViewController *redController = [[RedViewController alloc] initWithNibName:@”RedView” bundle:nil];
    self.redViewController = redController;
    —> [self.view insertSubview:redController.view atIndex:0];
    [redController release];

    2011-07-25 23:33:42.519 MultiViews[1833:207] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Could not load NIB in bundle: ‘NSBundle (loaded)’ with name ‘RedView”
    *** Call stack at first throw:

  6. thanks a lot! I had this error in Xcode 4.2. The error only appeared on the ‘real’ iOS devices, not on the simulator.
    I also had problems with the localisations (showing the keys, not the translations).

  7. addition: putting the MainWindow on the projects top level might produce problems, if you have a project with several localisations.
    I had the best result by deleting the MainWindow (after putting a copy to a safe place), then dragging the MainWindow back to the en.lproj folder. From there I dragged it on the top level of the Xcode project.
    Hope that doesN’t add confusion out there.

  8. I was unable to solve the problem and thought that I would just create a new project and copy all the folders in . So when I created the new project in Xcode 4 i noticed that it created a mainwindow.xib in the classes which was missing in the version i had from xcode3. So i just copy pasted that xib into my original project and it worked fine.

Comments are closed.