My learning style is such that when I learn something new, I jump into the fire and deal with the repercussion as they come. This approach has gotten me into a bit of trouble in the past, but for the most part, it has served me well. I tried a similar approach a few days ago attempting to write my first iPhone Cocoa Touch application.
The stumbling block was the NIB vs. the XIB interface files. I have had experiences with Visual Studio and have developed GUI interfaces in the past with it, so I figured it would not be too hard to learn Interface Builder. It turns out that I was right – it was not too hard, but I could have saved myself a lot of trouble by reading about it a bit more. All I knew going into it was that it was a GUI based UI designer that can be used to link code to the UI components.
XIB a NIB?
These (.xib and .nib) are the file extensions of an interface file in Xcode. I got stuck when I could not find the NIB file in my newly created project, because from what little documentation I read, it was supposed to be there. It turns out that a XIB file is the same thing as a NIB file. Except that a XIB file is stored on disk as a human readable XML file and a NIB file is stored on disk as a non-human readable binary format. The reason for this is to facilitate version control of the interface files and ease of comparison with diff tools. When the project is built, the NIB version is created from the XIB file. So after learning this fact, I stopped looking for the NIB file (I spent quite some time looking for it).
File’s Owner Proxy Object
When Interface Builder is opened, it opens a window containing four items. Among them, I would say that the most important to understand is the File’s Owner proxy object. The File’s Owner proxy object is exactly what its name suggests it is. It is the owner of the interface file – hence, the [Interface] File’s Owner. The File’s Owner proxy object loads the interface file when the application launches. It can also be thought of as the Controller in a (Model-View-Controller) MVC architectural pattern.
Once the File’s Owner proxy object is associated with a controller, you can Connect the object to a View object in the Interface Designer. I will not go into how to do this here because this article is intended to be more of a high level conceptual one so that you can build a mental schema to flesh out and upon which you can build. Without the mental framework, it is hard to make sense of new information.
Of course, the View object will have the UI elements like text fields, buttons, labels, and so forth to display on the screen. Once this is defined, you can use the Interface Builder to Connect or associate each control that is visible on the UI designer to the UI objects defined in your source code, as well as what action it should take once an event is received.
It was actually fairly simple once I had this basic understanding. Even though I already knew all this before, I still had to get familiar with the new terminologies and design tools to achieve anything useful. This is the part I dread the most when learning a new language or a tool. I am not learning anything new or novel conceptually, but I still have to invest the time to learn the tools and platform specific jargons.
In a future article, I intend to write a step by step tutorial with pictures and all that glorious stuff on a simple Cocoa Touch application that will hopefully flesh out the high level conceptual ideas in this article.
By the way, my purpose in writing these articles is an educational one for, not just you, but for me as well. It was helpful organizing what I learned in an article, and I hope it was helpful for you too.
If you enjoyed this post, make sure you subscribe to my RSS feed!
Development, iPhone Development
Cocoa, Cocoa Touch, Interface Builder, iPhone, Model-View-Controller, MVC, NIB, Xcode, XIB