Four score and minus seventy-two years ago, I brought forth on this internet a new blog post, conceived in levity, and dedicated to the proposition that no nibs are created. Since then, much has changed in the Mac world.
The problem is that you need to call
[myWindow setReleasedWhenClosed:NO]. In pre-ARC code, this would not be surprising to old-school Cocoa coders. However, ARC does not even allow you to use the
-autoreleasemethods, so you might think that
-setReleasedWhenClosed:would not be allowed either, or would at least be ignored. And you would be very wrong.
My goal is to make all my projects nibless. Nib and xib files have caused me no end of problems. Even files that haven’t been edited in years spontaneously stop working when Xcode is updated and its xib compiler changes. (Most of the problems manifested on previous OS versions, where it was harder to detect them and to test fixes.) And that’s to say nothing of the advantages that doing interfaces with code offers. I’m convinced that with current technology (e.g. Auto Layout, Swift), using Interface Builder is a poor time investment for non-temporary projects. As Johnson writes:
Initial nib UI implementation is faster, but it’ll haunt you forever.
I’m leaning the same way about Core Data models, except that there seem to be places where the frameworks really want to have a model file saved to disk.
Update (2016-10-19): Steven Woolgar:
Especially with ibtool failing randomly all the damned time.
I take back everything nice I said about Interface Builder a few weeks ago on Under The Radar.
After introducing NSStackView there is no more excuse to build any UIs in IB.
Update (2016-10-20): John Stricker:
If you were to restrict yourself to using interface builder for this layout, there are many limitations:
- you couldn’t as easily preserve two different styles of the view
- you wouldn’t be able to use loops, constants and enums to lay out the view
- you wouldn’t be able to adjust the content, size and layouts of the buttons all at once.
Update (2016-10-21): Peter N Lewis:
I use xib’s for everything in Keyboard Maestro. And have special Lint code to detect inconsistencies. Coming to the conclusion I'm an idiot.
Stay up-to-date by subscribing to the Comments RSS Feed for this post.