oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Build Your First Cocoa App
Pages: 1, 2, 3, 4

One thing to be careful about with this system has to do with deleting files from the Files and Groups list. You can delete files from the list by highlighting a file and clicking Delete. When you do this, you will see a dialog as illustrated below.

Screenshot of the delete dialog box.
The Delete dialog box.

Unless you want your file to disappear from the disk, do not click the Delete button. Go with the default option; you'll be glad you did. I had this problem once or twice when I wasn't paying close attention to what was going on.

Learning CocoaLearning Cocoa
By Apple Computer, Inc.
Table of Contents
Sample Chapter
Full Description
Read Online -- Safari

Associated with the Groups and Files list are several other tabbed views. The Bookmarks view holds placeholders for specific files or anything you want -- this is nice if you're working on a gargantuan application. I don't think we'll need that anytime soon. The Targets view allows you to set options that pertain to the compilation and execution process. Finally, Breakpoints refers to debugging breakpoints. A future column will be devoted to learning about the debugger.

The tabs running horizontally beneath the toolbar display status information returned by the compiler, runtime system, or debugger (Project Builder uses gcc and gdb for compiling and debugging. For those of you who have experience with these GNU tools, these tabbed views display what you would see in a terminal with these tools.) Finally, the pane that dominates the Project Window is the text editor where you do most of your "coding."

Creating a text editing application

I said in the beginning of the column that this application (as it is in this column) will require absolutely no coding on your part -- this is completely true. To see how this is true, let's go ahead and start with our application, a simple text editor. But first, a little background about how interfaces are built and stored in Cocoa.

Interface Builder

Interface Builder does exactly what you would expect from its name -- it provides an easy way to build complex and functional user interfaces. Interface Builder provides prototypes of almost all controls and interface components -- buttons, windows, scroll bars, and sliders -- that are available in Application Kit.

Interfaces are built, then, by dragging these components onto a main window, and connecting them with Objective-C objects; these objects are the link between your code and your interface. To illustrate the process of creating an application interface, I will discuss some of the elements of Interface Builder (IB), and we will create your first application.

NIB files

Cocoa handles interfaces through special files called NIB files, so named because of the file extension. These are the files that Interface Builder works with. A NIB file is basically an archive of every object that is part of you interface, with information about their attributes and connections between other objects. I mentioned previously that any object-oriented application is composed of a network of objects; NIB files are an archive of the object sub-network that deals with interfaces.

Every application with a graphical user interface has a main NIB file that is associated with the main window and main menu of that application. An application may also have any number of auxiliary NIB files. Usually, there is a NIB file associated with each unique window in an application. For example, a preference window would have a NIB file separate from the main NIB file.

Document-based applications such as the one we are creating have two NIB files initially. One archives the application-wide interface, which is usually just the menu bar at the top of the screen. The other NIB file keeps all the objects and information related to the document's interface, or rather the interface of the window in which your document's data is displayed. This interface may be nothing more than a scrollbar on the right side and a ruler across the top; nevertheless, it's an interface that users interact with and requires building.

(By the way, as a side note, the .nib extension is one of the relics of the NeXT operating systemm that lurk in Mac OS X that I spoke of in the first column -- NIB stands for NeXT Interface Builder. And while we're on the subject, you've probably wondered at some point or another why every Cocoa class name is preceded by an "NS-NS" which stands for NextStep. I just love this stuff!)

Pages: 1, 2, 3, 4

Next Pagearrow