One of the crown jewels of the Cocoa development environment is Interface Builder, a tool for building graphical user interfaces.

Interface Builder creates and stores user interfaces in nib files. Perhaps one of the most important aspects of Interface Builder is that it does not generate source code. Nibs are bundles that contain information and archived objects (in this context often referred to as “freeze-dried”) that constitute the elements of the user interface (such as windows, widgets and menus, as well as non-UI objects) as they were arranged and configured with Interface Builder. When a nib file is loaded at run time, the elements are reconstituted exactly as they were in Interface Builder.

Every application has a MainMenu.nib file that contains the application’s main menu structure. For simple applications, this nib might also contain the application’s main window. More advanced applications generally have a number of nib files, each of which defines part of the user interface.

From a design perspective, creating a nib for each window (or logical group of windows) facilitates reuse. From a performance perspective, loading nibs into memory takes time, so it is best to keep them small. Thus, when the application launches, it needs to load only the nib containing the first window the user sees, rather than every window in the application, many of which the user may never open (such as the About Box).

Outlets and Actions

Nib files contain definitions for objects that can ...

Get Cocoa in a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.