Learn Objective-C on the Mac - Mark Dalrymple [4]
Cocoa provides a class for just about every one of your development needs. There are Cocoa classes for each piece of the Mac OS X user interface, from windows to menus, scrollbars to buttons, images to icons. If you can think of a user interface element you’d like to add to your own application, chances are very good that element is already implemented as a Cocoa class.
Another benefit of using Cocoa is that it is tightly integrated with Mac OS X. Build your application using Cocoa, and your application will play well with others and will interface seamlessly with Mac OS X elements like the Finder and the Dock.
WHEN IS 20 YEARS NOT 20 YEARS?
Cocoa has been around in one form or another since 1986. The technologies that we call Cocoa evolved from the NeXTStep AppKit, the application building tools developed for the NeXT platform. When Apple bought NeXT in 1996, they began building a new version of the Mac OS, what we now know as Mac OS X, basing much of the new operating system on technologies acquired from NeXT.
As Mac OS X evolved, so did Cocoa. Apple added technologies from the classic Mac OS, like QuickTime, as well as completely new technologies, like the Quartz rendering system that enables all the fancy visual effects and animation that OS X uses. They also made sure that they kept the Mac’s famed ease-of-use in the process.
Bottom line: Cocoa is constantly evolving and expanding. The development tools, libraries, and frameworks you’ll be learning in this book are the result of more than 20 years of experimentation and refinement.
Get a Mac and Download the Tools
Before you can begin creating applications with Cocoa, you’ll need a Macintosh computer. It doesn’t have to be the newest or the most powerful Mac; in fact, pretty much any Mac that’s been made in the last six or seven years or so will work just fine for building the exercises in this book. As you become more serious about writing software, you may find it’s worth investing in a newer or faster machine, but for now just about any Mac made this millennium will work fine for learning what you need to learn. Any Intel-based Mac, and almost all PowerPC Macs with a G4 or G5 processor will run Mac OS X 10.5 (Leopard). If you want to run the newer Mac OS X 10.6 (Snow Leopard), the PowerPC machines won’t do; you’ll need to have an Intel machine.
You’ll also need to join Apple Developer Connection (ADC), which is Apple’s developer relations organization. There are paid memberships, but the basic membership is free. You’ll need at least the free membership in order to download Apple’s development tools, which you’ll need to do in order to write software in Cocoa. To join ADC, open up your web browser and navigate to http://developer.apple.com/mac/. If you already have an Apple ID, press the Log in button and enter your info. If you are new to Apple’s online services, click the register link and create your account.
Once you are a bona fide ADC member, you’ll be able to download Apple’s developer tools. These tools are listed on the main Mac Dev Center page under the heading Xcode. The link for downloading Xcode actually downloads a full suite of developer tools, including all the software you’ll need for working with Cocoa.
Once you are logged in, find the version of Xcode that’s appropriate for your version of Mac OS X, and click on the Xcode link to start the download. A .dmg disk image file will download. Last we checked, the download was about a gigabyte, so it might take a few minutes. Once it is done downloading, double-click the .dmg file to mount the disk image. Next, double-click the installer file inside the disk image and start that install.
If you don’t have a high-speed internet connection, you may find the developer tools on one of the CDs or DVDs that came with your Mac. That said, if possible, you should try to find a way to download the latest version.
NOTE: If you’ve already installed the iPhone SDK, then