Wednesday, January 3, 2007

Can't Touch Nibs

I heard something recently on the grapevine that I haven't yet seen in the blogosphere, so I thought I should mention it. If there's any demand, I'll dig deeper into the code and post further details.

- Open up Interface Builder, create and save a new blank nib file(Cocoa/Application).
- Locate the new nib in Finder, and 'Show Package Contents'.
- Delete 'classes.nib' and 'info.nib', but leave 'keyedobjects.nib'.
- Attempt to reopen the modified nib package in IB.
- Marvel at IB's reluctance to open the file for editing.

Ok, so IB won't open it, so what?

It turns out that IB's 'Open' command and [NSBundle loadNibNamed:owner:] have entirely different requirements regarding the contents of the nib package we're attempting to load/open.

The reason this came to light was that someone was trying to have a look at XCode 2.4.x nibs, which lack the 2 files we deleted above. I'm not sure when Apple started deleting those 2 files, but on my box(XCode 2.2) I have all 3 internal files in 'PBX.nib' and 'PBXActiveOperationsPanel.nib'. But obviously, since XCode 2.4.x launches with no errors, those 2 deleted files aren't needed at runtime.

So, at first glance, the moral of the story is- you can keep your users from opening your nibs in IB(thus keeping those damned GUI hackers at bay) by simply deleting the aforementioned files from your nibs, possibly with a custom build phase.

But just for fun, we glanced twice.

- Repeat the 'create and save a blank nib file' steps, but this time, don't delete anything.
- Copy 'classes.nib' and 'info.nib' from the newly created nib package into the unopenable nib package.
- Marvel at IB's willingness to open the previously unopenable file for editing.

I am sure that there is some information lost in the translation, but this seems to be a good start. As always, any comments/questions/suggestions are welcome.


Anonymous said...

very interesting. I have been trying to hack some customizations into adium and was going nuts trying to open up the .nibs.... followed your hack and opened right up.

dalmazio said...

Thanks for this. I was working with an older project, and couldn't understand why Xcode could not open the MainMenu.nib file. Adding the info.nib from an empty project corrected this. Then I could just save to .xib format. Thanks again!

Araignée said...
This comment has been removed by the author.
Araignée said...

Just ran across this today. I've posted the same hack here should anyone need step-by-step instructions. This is particularly an issue in Snow Leopard, as I believe they shrunk app sizes by removing these "unnecessary" .nibs (as per this).