Polishing Your Development Tools for Cocoa Programming

Cocoa is one kind of programming that you can perform with Apple's Developer Tools. Cocoa is a collection of tools and libraries that allows you to get the most out of Mac OS X programming. Many features make Cocoa great, including the following:

  • Modular object-oriented design
  • Use of frameworks
  • Visual interface design

Why program with Cocoa?

Object-oriented programming is all the rage these days, and for good reason. By programming with an object-oriented design, your code can more closely model items in the real world.

The use of frameworks is another great aspect of Cocoa development. Experienced programmers may be tempted to call them by another name — libraries. Frameworks are collections of classes that provide you, the Cocoa developer, with a specific type of functionality.

The object-oriented nature of Cocoa, combined with a large collection of frameworks to perform all sorts of tasks, forms an unbeatable code-reuse duo. Computer programmers can be a lazy bunch, not wanting to repeat a single task. To aid developers in their pursuit of reusable code, Cocoa offers a wide array of classes, tools, and code. After you've completed some programming tasks, you can even store the results in your own framework for use in other projects. Thus, Apple gives you reusable code out of the box, and you can reuse your own code as well. The object-oriented design of Cocoa makes this reuse possible.

To help facilitate your Cocoa development, Apple was nice enough to provide you with a large selection of tools and utilities. With these tools, you can begin creating Cocoa software from the ground up. When you're finished programming, the tools will even build the application, prepare it for distribution, and put together an installer.

In the toolkit

To begin programming with Cocoa, you need to find the development tools. They reside in the following directory on your hard drive.


If you don't have them, you'll need to install the tools.

If your copy of Mac OS X didn't come with a copy of the Developer Tools CD, you can still get your hands on a copy of the Developer Tools software through the Internet. Visit the Apple Developer Connection to register for a free account:


You won't need all the applications that Apple provides in the /Developer/Applications directory. In fact, you can probably get away with using only two: Project Builder and Interface Builder. Your Cocoa development process, including the Project Builder and Interface Builder applications, might look like this:

1. Create a Cocoa project.

Most Cocoa projects begin their lives in Project Builder. Project Builder is the heart of your Cocoa development. This is where you store the various elements that make up your Cocoa projects.

2. Build an interface and add it to the project.

Joined at the hip, Interface Builder forms the other half of the conjoined twins that are Apple's Developer Tools. Interface Builder is a WYSIWYG (what you see is what you get) editor for creating attractive Mac OS X interfaces that conform to Apple's Aqua standards. Interface Builder does other tricks too, including writing some of your code for you in Project Builder.

3. Add some code to the project.

You've built an interface, and now it's time to make it do something. You use Project Builder again for this task, because it puts a suite of code-editing tools in your hands. You get built-in documentation, plus code that's colored to make it easier to perform your programming tasks.

4. Test the code.

Again, Project Builder interfaces with the included debugging tools to help you produce bug-free code. There's also nothing wrong with trial-and-error testing, where you use your application, looking for mistakes or errors in its operation.

5. Build an application.

Project Builder compiles, links, and builds your final executable application.

Project Builder

Project Builder is the main application that you use for all your Cocoa projects. Project Builder serves a number of roles in the Cocoa development process.

Project Builder acts as the central repository for all the files in your Cocoa projects. Using a familiar document approach, Project Builder lets you organize the components of a Cocoa project in one easy-to-use document.

You use Project Builder also to write and edit Cocoa source code. As you write code for a project, Project Builder guides you by coloring the syntax. It also offers convenient one-click access to all the functions in your code.

Your Cocoa project may have other types of files beyond code, and Project Builder is prepared to help you work with them. For example, if you want to include images in your project, Project Builder lets you view them in the main project window without skipping a beat. There's no need to use another application to view those images. Project Builder displays them right in the code editor.

When you get stuck, Project Builder gives you access to the complete collection of Cocoa documentation. You can view and navigate the documentation with Project Builder in much the same way as you would a Web browser.

After you complete your Cocoa project, you use Project Builder to compile, link, and build a final application. You can then distribute the application to friends, co-workers, and even the world (as long as they use Mac OS X).

Project Builder wears many hats. If you're accustomed to other development environments, you may be surprised to discover that Project Builder performs tasks that require multiple tools in other environments.

For example, Project Builder functions as a

  • Project organizer, managing files and resources in your Cocoa projects
  • Code editor, allowing you to write and edit Cocoa code
  • Browser, displaying built-in documentation or other kinds of resources in your Cocoa projects
  • Compiler and linker, spitting out a complete Cocoa application at the end of the development process.

Interface Builder

Interface Builder is a constant companion to Project Builder. Interface Builder's main purpose is to create interfaces. With it, you can build Aqua interfaces that adhere to Apple's Human Interface Guidelines.

Interface Builder provides a complete set of controls that you can add to your application. From windows and drawers to buttons and sliders, Interface Builder gives you drag-and-drop access to a full suite of interface elements to make your software the best it can be. Don't forget that Interface Builder is an Apple product. No one knows the Macintosh user interface better than Apple, so you can be certain that the controls in Interface Builder follow the strictest Apple guidelines.

Interface Builder's features aren't limited to WYSIWYG interface editing. You can also create classes that have no visual representation. Although you don't actually write the code in Interface Builder for your classes, you do define the basic structures and methods for them there. You can also connect the interface to your classes using simple drag-and-drop techniques.

After you complete an interface, Interface Builder creates the header and implementation files for you and then inserts them into the desired Project Builder project. Although Interface Builder's strongest features pertain to designing and creating great-looking interfaces, many other features make it much more than an interface-building tool. It plays a big part in the Cocoa programming experience.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.