Cocoa was designed to make application development simple and to take a lot of the hard, repetitive work
out of application development. Many common features of applications that users may take for granted are
quite difficult to program. This chapter describes those integrated components of Cocoa. You may be surprised
how many classes and features come packaged with Cocoa to minimize the time you spend coding.
For Free with Cocoa
The simplest Cocoa application, even one without a line of code added to it, includes a wealth of features
you get "for free." You do not have to program these features yourself. You can see this when you test an
interface in Interface Builder.
Application and Window Behavior
In the Interface Builder test mode, Currency Converter behaves almost like any other application on the
screen. Click elsewhere on the screen, and Currency Converter is deactivated, becoming totally or partially
obscured by the windows of other applications.
If you closed your application, run it again. Once the Currency Converter window is open, move it around
by its title bar. Here are some other tests you can do:
1.
Open the Edit menu. Its items appear and then disappear when you release the mouse button, as with
any application menu.
2.
Click the miniaturize button. Click the window's icon in the Dock to get the application back.
3.
Click the close button; the Currency Converter window disappears.
If you hadn't configured the Currency Converter window in Interface Builder to remove the resize box, you
could resize it now. You could also have set the autoresizing attributes of the window and its views so that
the window's elements would resize proportionally to the resized window or would retain their initial size
(see Interface Builder Help for details on autoresizing).
Controls and Text
The buttons and text fields of Currency Converter come with many built-in behaviors. Notice that the Convert
button pulsates (as is the default for buttons associated with the Return key). Click the Convert button. Notice
how the button is highlighted for a moment.
If you had buttons of a different style, they would also respond in characteristic ways to mouse clicks.
For Free with Cocoa
71
2007-10-31 | © 2007 Apple Inc. All Rights Reserved.
CHAPTER 8
Expanding on the Basics