Online Book Reader

Home Category

Learn Objective-C on the Mac - Mark Dalrymple [7]

By Root 907 0
to the left of it. That will expand the Resources group to reveal three files that were created automatically for you. We’ll ignore the first two files for the moment, and revisit them later. The third file is named MainMenu.xib.

NOTE: You might have noticed that MainMenu.xib has a disclosure triangle next to it, even though it’s a single file and not a group or folder. Disclosure triangles are also used for files that are localizable, which means they’ve been set up so they can be translated into other languages. If you press the disclosure triangle next to Mainmenu.xib, you’ll notice a single sub-item named after the language specified in International preference pane in your System Settings. Despite the disclosure triangle, double-clicking on MainMenu.xib will open the nib file for editing.

In your project window, double-click on MainMenu.xib. This should launch Interface Builder, the editor specifically designed to edit .xib files. (See Figure 2-4.) As you’ll learn as you make your way through this book, Xcode and Interface Builder go together like bacon and eggs or, if you prefer, like Conan O’Brien and Andy Richter. The idea here is to use Xcode to organize your program’s resources and code, and Interface Builder to design your program’s user interface. There’s more to it than that, but that’s a pretty accurate high-level view. You’ll be using Interface Builder throughout this book.

The file MainMenu.xib is known as a nib file. Huh? A nib file? Why not a xib file? Well, for starters, xib is awfully hard to pronounce. But more importantly, the term nib is a holdover from an earlier, simpler time. The precursors to Cocoa and to the modern Xcode/Interface Builder development tools were developed by NeXT, Inc., a company started by Steve Jobs in 1985. The name “.nib” originally stood for NeXT Interface Builder. Over time, NeXT was acquired by Apple, and the nib format evolved into a newer, XML-based format. This combination of XML and Interface Builder yielded the new .xib extension. Nonetheless, the name “nib file” stuck, and most developers still call their .xib files “nib files.”

WARNING: You’ll find the file MainMenu.xib in every Cocoa project you create in Xcode. This is a special file. Treat it as such. Do not move, rename, or otherwise annoy the file. Unless we tell you to. When your application gets launched, it will automatically load the contents of MainMenu.xib into memory. MainMenu.xib contains critical information, including your application’s menu bar and main window (if it has one). Over time, you’ll learn all there is to know about nib files and will be rolling your very own. For the moment, patience, and hands off.

Figure 2-4. MainMenu.xib opened in Interface Builder

Exploring the Nib File


Once Interface Builder has launched, a series of windows will appear. A large blank window named Window (Figure 2-4, left middle) represents your application’s main window. As you’ll see in a moment, you’ll use this window to lay out the contents of the window that will be displayed when your program is launched. The Cocoa Application project template we used to create this project assumed that you would have at least one window in your application, and it created that window instance for you.

The short, wide window labeled MainMenu (Figure 2-4, lower left) represents your application’s menu bar. Changes to this window will be reflected in the menu bar that appears when your application is launched.

The window in the upper left corner with the title MainMenu.nib (English) is your nib’s main window. Don’t confuse this window with the window named Window (which represents your application’s main window). The window titled MainMenu.nib (English) is basically the nib’s main document window, which includes all the windows, views, and other objects contained in the nib. To distinguish this from the windows it contains, we usually refer to this window as the “main nib window.” If you close a nib’s main window, all the other windows relating to that nib will close as well.

The Library


On the

Return Main Page Previous Page Next Page

®Online Book Reader