Matt Gemmell

My new book CHANGER is out now!

An action-adventure novel — book 1 in the KESTREL series.

★★★★★ — Amazon

CoreData Application template issue on Tiger

Development 1 min read

I’m posting this mostly so that others who encounter the same problem have a fighting chance of finding this information on Google.

I ran into an issue with an app created using the CoreData Application template in Xcode (not either of the two CoreData Document-based Application templates, though this may well affect those too). I’ve reproduced this issue several times, as have a few others including Daniel Jalkut. The issue seems to be fixed on the current Leopard seed, for what it’s worth.

Basically, you create a simple CoreData application, including an entity and a relevant controller object in the nib (say an NSArrayController). Hook it all up appropriately. I hooked up File > New to the “add:” action in the controller, for convenience. Run the app, make some new entities, and quit. It’ll all work fine, and you’ll see from the data-file (an XML format file in your Application Support folder by default) that everything was saved properly etc.

Now, the crazy part. The MainMenu.nib which is created as part of the template has an empty window in it. I didn’t need that window, so I deleted it… and the app stopped working. Specifically, it just stops responding during the nib-loading phase the next time you launch it. No spinning pizza of death, no CPU activity, no exceptions or console messages. You can’t open any menus or do anything with it.

I experimented, and this only happens if (1) there is previously-saved data in the permanent store, which the app must then load, AND (2) you’ve deleted the window from the nib. If you remove either of those conditions, it runs fine. Three others have reproduced this on Tiger, and I’ve reproduced it three times myself. The only “solution” seems to be… make sure there’s a window in the nib. It doesn’t have to be the original window; any old window will do. You can readily delete the original one then drag a new one from the palette, and all is happy in toytown.

Kind of bizarre, huh? If you want to try it yourself, grab this sample app. Run it and choose File > New a bunch of times so that it makes some entities, then quit it. It’ll save the data. Now open the nib in Interface Builder, delete the window, and save the nib. Build and Run the app again and watch in amazement as it does… not a lot.

As I said, this seems to be already fixed in Leopard (9A527), but I wanted to post this to hopefully save others the 2 hours of head-scratching I went through last night. Thanks to Daniel and the other #macdev/#macsb guys for reproducing the issue, by the way.

Bottom line is that, if you’re seeing the same behaviour, make sure there’s a window in your MainMenu.nib. It doesn’t have to ever be shown (so uncheck Visible at Launch Time if you like). It just has to be there. Go figure.