Chapter 1. Introduction to Cocoa

Cocoa is an extensive library of reusable software components used for building applications that run on Mac OS X. You can think of Cocoa as a large set of application building blocks that you can use “off the shelf” or adapt for your specific needs. This chapter gives you a high-level overview of those building blocks, shows you how they are organized, and explains the features they provide.

Cocoa poses a learning curve for newcomers, but once you learn to use it, application development will suddenly seem far easier and more fun. Because the Cocoa frameworks give you so much fundamental application functionality “for free,” you can spend your time and creative energy building new technology, not reinventing the wheel.

Cocoa has actually been around a long time—almost as long as the Macintosh itself. That’s because it is to a large extent based on OpenStep, which as NeXTSTEP was introduced in 1987. OpenStep evolved through many releases, was adopted by many companies as their development and deployment environment of choice, and received glowing reviews in the press. It was, and continues to be, solid technology, based on a design that was years ahead of anything else in the market and it has been perfected year after year.

Let’s take a closer look at Cocoa’s features and frameworks to give you a better idea of how to use Cocoa to create various applications. Figure 1.1 shows the general structure of the Mac OS X system software.

Cocoa is part of Mac OS X’s system software

Figure 1-1. Cocoa is part of Mac OS X’s system software

Cocoa is one of the principal application environments for Mac OS X. Cocoa’s advanced object-oriented APIs allow you to develop applications written in Java and Objective-C. Cocoa is an integrated set of shared object libraries, or frameworks, plus a runtime system and development environment that does three principal things:

  • Insulates programs from the internal workings of the core operating system, mediating access to system resources and preventing programs from trashing one another’s address space

  • Provides all infrastructure that programs typically need

  • Brings the benefits of object orientation to program development

You can think of Cocoa as a layer of objects that acts as mediator and facilitator between programs and the core operating system. The stability, performance, and reliability of these programs therefore depend on the underlying core operating system having these characteristics.

Cocoa Features

This section describes some of the high-level features available to you when you develop using Cocoa.

Imaging and Printing Model

The imaging and printing model for Mac OS X is Adobe’s Portable Document Format (PDF). Unlike in previous versions of the Mac OS, the same mechanism is used to view and print what appears on the screen. You no longer have to duplicate code to send output both to the screen and to PostScript-based devices. The best of Apple’s graphics technologies, including ColorSync and QuickDraw GX typography, is being brought to core graphics.


Cocoa applications can take advantage of some of the most powerful technologies available—QuickTime and OpenGL.


Mac OS X comes packaged with the latest version of QuickTime. QuickTime is a powerful multimedia technology used for manipulating, enhancing, and storing video, sound, animation, graphics, text, music, and even 360-degree virtual reality.

QuickTime streaming allows users to view live and video-on-demand movies using the industry-standard protocols RTP (Real-Time Transport Protocol) and RTSP (Real-Time Streaming Protocol). Users can view streaming live broadcasts, previously recorded movies, or a mixture of both. Broadcasts can be either unicast (one-to-one) or multicast (one-to-many).


Mac OS X includes Apple’s highly optimized implementation of OpenGL as the system API and library for three-dimensional (3D) graphics. OpenGL is an industry-wide standard for developing portable 3D graphics applications. OpenGL is one of the most widely adopted graphics API standards today, which makes code written to OpenGL highly portable. It is specifically designed for games, animation, CAD/CAM, medical imaging, and other applications that need a rich, robust framework for visualizing shapes in two and three dimensions. Mac OS X’s version of OpenGL produces consistently high-quality graphical images at a high level of performance.

OpenGL offers a broad and powerful set of imaging functions, including texture mapping, hidden surface removal, alpha blending (transparency), antialiasing, pixel operations, viewing and modeling transformations, atmospheric effects (fog, smoke, and haze), and other special effects. Each OpenGL command directs a drawing action or causes special effects, and developers can create lists of these commands for repetitive effects. Although OpenGL is largely independent of the windowing characteristics of each operating system, special “glue” routines are implemented to enable OpenGL to work in an operating system’s windowing environment.


Apple intends for Mac OS X to be a major technological force on the Internet. The development platform features APIs for Internet-based mail, messaging, directories, and security services. Cocoa also offers built-in HTML rendering capabilities.

Localization and Internationalization

You can easily localize Cocoa applications largely because of a well-designed localization architecture and Unicode support, both built into the frameworks. In this architecture, user interface elements are kept separate from the executable. It’s therefore possible to have a single code base that is qualified for various locales. You can even have multiple localizations bundled with one application, greatly reducing the overall footprint of an application in its various localizations. Your localization bundles can be added to or removed from an existing application easily, making new localizations distributable through updaters.

Because Cocoa uses Unicode 2.0 as its native character set, applications can easily handle all of the world’s living languages. The prevalence of Unicode also eliminates many character-encoding hassles. To help you handle non-Unicode text, Cocoa also provides APIs to help you translate between Unicode and other major character sets in use today.

Apple’s development environment supports localization in several important ways. It gives you an easy way to identify which files are to be localized (and for which language). It also enables you to create a series of archivable user interfaces, each designed for a particular locale.

Text and Fonts

Cocoa offers a powerful set of text services that can be readily adapted by text-intensive applications requiring high performance. These services, which can support text buffers as large as the virtual memory space, include kerning, ligatures, tab formatting, and rulers. The text system also supports embedded graphics and other inline attachments.

Cocoa supports a variety of font formats, including Type 1 PostScript, Type 3 PostScript, Type 42 PostScript, and TrueType (including the typographic capabilities of TrueType GX). The goal for Mac OS X is an open font architecture that makes it easy for users to work with any font format they want.

Component Technologies

One of the key advantages of Cocoa as a development environment is the capability to develop programs quickly and easily by assembling reusable components. With the proper programming tools and a little work, you can build Cocoa components that can be packaged and distributed for use by others. Applications are an obvious example of this component technology, but there are others. With Cocoa and Apple’s development tools, you can create:

  • Frameworks that other developers can use to create programs by writing code based on the framework APIs

  • Bundles containing executable code and associated resources that programs can load dynamically

  • Palettes containing custom user interface objects that other developers can drag and drop into their own user interfaces using Mac OS X development tools

With Cocoa’s component architecture, you can easily create and distribute extensions and plug-ins for applications.

Get Learning Cocoa now with the O’Reilly learning platform.

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