Organization of This Book

This book is divided into the following four parts.

Part I, Cocoa Overview

The first part of this book introduces the Mac OS X interface (Aqua), Cocoa developer tools, the Objective-C language in which Cocoa is written, and Cocoa programming itself.

Chapter 1, contains an overview of Aqua features and behaviors that programmers should understand so that they can build applications that look and feel like Mac OS X applications. In particular, programmers writing new Mac OS X applications should follow Aqua’s stringent interface guidelines so as not to confuse users. Chapter 1 also contains a tutorial on how to become a power user of Mac OS X and the Aqua GUI. Although people familiar with Mac OS X and Aqua might want to skip this chapter, it contains many hints and shortcuts with which even experienced Cocoa programmers may not be familiar.

Chapter 2, contains an overview of Project Builder, Interface Builder, and the gdb debugger, the three most important Cocoa developer tools. It also contains an introduction to the (Unix) Terminal and several other useful developer tools.

Chapter 3, uses Interface Builder, a revolutionary program for drawing and wiring together objects in application interfaces, to build a very simple application without any coding whatsoever. We’ll use it to create a little program that plays a sound and updates a text field when the user moves a slider.

Chapter 4, builds an application from the ground up, using only Objective-C and the Cocoa Application Kit. This will give you a hands-on feel for what Interface Builder is actually doing. We also use this chapter to introduce the syntax and framework of the Objective-C language.

Part II, Calculator: Building a Simple Application

The second part of this book is focused on building a simple application — a calculator — which we extend piece by piece through four chapters.

Chapter 5, introduces the Calculator application project. We create the calculator’s window and build a simple Objective-C object that handles the math features of the calculator. At the end of the chapter, you’ll have a working four-function calculator.

Chapter 6, adds an About box to the Calculator application. This gives us an opportunity to use some additional features of Interface Builder. We also clarify Cocoa’s system of outlets, connections, and actions. At the end of this chapter, we show you how to add an application icon that identifies the application in the Finder and the Dock.

Chapter 7, introduces the concept of delegation — designating objects to perform functions for other objects. In this chapter, we make the four-function calculator work with other bases (binary, octal, and hexadecimal) and use delegation to set the initial base. In the second half of the chapter, we use an example of programmatically resizing a window to introduce Cocoa’s NSWindow and NSView classes.

Chapter 8, introduces the responder chain, the chain of objects that Cocoa uses to process events such as keypresses and mouseclicks. At the end of the chapter, we use our newfound knowledge to modify the calculator so that users can enter numbers by typing on the keyboard, in addition to simply clicking with the mouse. This chapter completes our work on the Calculator application.

Chapter 9, provides background on the Mach operating system upon which Mac OS X is based and on the Quartz Window Server that Mac OS X uses to draw on the screen and manage events. This chapter provides useful, general information that will help us build more complicated applications in subsequent chapters.

Part III, MathPaper: A Multiple-Document, Multiprocess Application

The third part of this book focuses on building a new application called MathPaper. MathPaper is similar to a word processor in that it supports multiple windows, but it behaves very differently. Users can enter mathematical expressions in a MathPaper window, and the application will solve the expressions that were typed. The application uses a back-end mathematical processor called Evaluator to do the mathematical calculations. Chapter 15 leaves MathPaper but includes several small examples that demonstrate drawing in NSView objects.

Chapter 10, introduces the MathPaper application and shows you how to write applications that control multiple windows. We also build MathPaper’s back end (Evaluator) in this chapter, but we don’t connect it to the application until the next chapter.

Chapter 11, ties MathPaper’s front and back ends together with a Cocoa object that can spawn subprocesses. By the end of this chapter, MathPaper will be able to calculate mathematical expressions typed in by users.

Chapter 12, discusses Microsoft’s Rich Text Format (RTF), which Cocoa uses to encode information such as font, point size, and alignment into a text stream. We use RTF to make MathPaper’s output look more professional.

Chapter 13, introduces Cocoa’s facilities for dealing with document files. Using MathPaper, we show how to register a filename extension with the Finder, how to archive information into streams, and how to save and load files with the Save and Open dialogs.

Chapter 14, shows the basics of how to draw in a window. We demonstrate this by making an animated About box for the MathPaper application.

Chapter 15, leaves MathPaper. The chapter explores the NSView class in general and the drawRect: method in particular. We build several small programs in this chapter to show how NSViews work.

Part IV, GraphPaper: A Multithreaded, Mouse-Tracking Application

The fourth part of this book focuses on building one last major application, called GraphPaper. Given a range and step, GraphPaper will graph a mathematical function in color and use mouseovers to identify graph points. We also embed in GraphPaper many of the standard features of commercial Mac OS X applications, such as services, copy and paste, and the use of the Mac OS X preferences database.

Chapter 16, introduces GraphPaper, a complex application that graphs a function in two dimensions. This application is multithreaded, meaning that it has several execution threads and does several different things at the same time. It uses the same Evaluator back end that MathPaper used.

Chapter 17, continues our discussion about drawing in color with Quartz. We show how to enable users to change the color of the graph, axes, and label via a Preferences dialog.

Chapter 18, shows how to catch mouse moves and handle more kinds of mouse events. We do this by modifying the GraphPaper application so that it displays the (x,y) coordinates of the graph for wherever the user places the mouse.

Chapter 19, shows how to put a zoom button on a view to change its magnification. We also show how to save a graphic image as a PDF file or as a TIFF image.

Chapter 20, shows how to put data on and remove data from the pasteboard (clipboard). We also show how to make GraphPaper a Mac OS X service that shows up in the Services menu, so you can graph functions that are selected in other applications.

Chapter 21, shows how to build a multi-view Preference panel and how to save its contents into the defaults database.

This book also contains an appendix, Appendix A, which lists other books and online resources that you might find helpful in programming Cocoa.

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.