Creating Cocoa applications programatically (i.e. NIB-less)Posted on May 21st, 2008 4 comments
"Why on earth would you want to create a Cocoa application without using Interface builder?"
That's the basic reaction you get if you try to seek out help online in writing a Cocoa application from scratch.
There may not be a lot of valid reasons but if there is at least one reasonable answer, then the question should be moot.
Our applications at DVFilm are cross-platform. The user interfaces are very simple. The majority of the code is written in C/C++ and in the business logic. So I have not given up on the idea that the simple form-based UI can be written in such a way that the majority can be shared between Windows and Mac.
There, that's my "reasonable" explanation on why I am crazy enough to consider creating a Cocoa application programmatically. If that doesn't satisfy, here is another reason.
I have inherited a Carbon application (a QT template app, actually) and simply want to add a single dialog using existing Cocoa code.
If neither answer satisfies, I DON'T CARE. I do appreciate all the arguments for stopping my Tilting at Windmills but THEY don't satisfy ME. If you can't bring yourself to suspend your disbelief and offer help, I'll figure it out on my own.
4 responses to “Creating Cocoa applications programatically (i.e. NIB-less)”
Check out “Working without a NIB” from Lap Cat http://lapcatsoftware.com/blog/2007/07/10/working-without-a-nib-part-5-open-recent-menu/ , that might help.
I am new to the Mac from a development perspective and am looking at making a highly dynamic interface. I am not sure that the IB/.nib approach is going to support what I need to do.
I appreciate the advice given on the linked-to pages that doing it manually will be difficult and I am very much in favour of maintaining platform consistency, but I am beginning to feel that my requirements are just too low-level for IB to be of real use. I am also used to the GTK+/QT method of doing things so it doesn’t really seem like much of an issue to me.
What I’m wondering is are there bindings for scripting lanugages like Ruby and Python that work the same way as they do for GTK+ and QT — i.e. allow the interface to be specified within the script? I know that bindings exist for Cocoa already but it seems they all assume the existence of .nibs and an Obj-C wrapper. I’m still at an early stage of my research so perhaps this is a question I will find an answer to in the near future.
It is good to know that others share the same views and that the iPhone doesn’t support .nibs — maybe this means some good techniques and perhaps better support will emerge for .nib-less programming on the desktop too.
Thanks for a positive and informative article on the subject!
You might take a look at wxCocoa the cocoa port in the wxWidgets project. Here all views are (by necessity) created programatically.
I spoke informally, a year or so informally to an engineer from Adobe who was working on a port of Acrobat from Carbon to Cocoa suggests that they do much the same thing. His comments were that there are some bugs and caveats in doing this because cocoa views have not been designed with this in mind – but it is not that hard to do and is less buggy than Carbon.
I just wondered off to google, after finishing an article on this subject for my blog, to see if it showed up on search results. And I just saw this page and figured I’d advertise for the article I just did.
Here you can see how I do it: http://casperbhansen.wordpress.com/2010/08/15/dev-tip-nibless-development/
Leave a reply