Cocoa(R) Programming for Mac(R) OS X

by
Edition: 2nd
Format: Paperback
Pub. Date: 2004-01-01
Publisher(s): Addison-Wesley Professional
  • Free Shipping Icon

    This Item Qualifies for Free Shipping!*

    *Excludes marketplace orders.

List Price: $52.49

Rent Book

Select for Price
There was a problem. Please try again later.

New Book

We're Sorry
Sold Out

Used Book

We're Sorry
Sold Out

eBook

We're Sorry
Not Available

How Marketplace Works:

  • This item is offered by an independent seller and not shipped from our warehouse
  • Item details like edition and cover design may differ from our description; see seller's comments before ordering.
  • Sellers much confirm and ship within two business days; otherwise, the order will be cancelled and refunded.
  • Marketplace purchases cannot be returned to eCampus.com. Contact the seller directly for inquiries; if no response within two days, contact customer service.
  • Additional shipping costs apply to Marketplace purchases. Review shipping costs at checkout.

Summary

Harness the power of Cocoa's object-oriented software development environment with this book that is completely updated for Mac OS X 10.2. Cocoa has quickly gained recognition as the leading development framework for building OS X applications. Users will understand the common features found in Cocoa's tools: InterfaceBuilder, ProjectBuilder, the GCC compiler and the GDB debugger.

Table of Contents

Preface xvii
Acknowledgments xix
Chapter 1 Cocoa: What Is It? 1(10)
A Little History
1(3)
Tools
4(1)
Language
4(1)
Objects, Classes, Methods, and Messages
5(1)
Frameworks
6(1)
How to Read This Book
7(1)
Typographical Conventions
7(1)
Common Mistakes
8(1)
How to Learn
8(3)
Chapter 2 Let's Get Started 11(26)
In Xcode
11(5)
Create a New Project
12(3)
The main Function
15(1)
In Interface Builder
16(10)
The Standard Palettes
16(1)
The Blank Window
17(1)
Lay Out the Interface
17(2)
The Doc Window
19(1)
Create a Class
20(3)
Create an Instance
23(1)
Make Connections
24(2)
Back in Xcode
26(6)
Types and Constants in Objective-C
28(1)
Look at the I leader File
28(1)
Edit the Implementation File
29(1)
Build and Run
30(1)
awakeFromNib
31(1)
Documentation
32(1)
What Have You Done?
33(4)
Chapter 3 Objective-C 37(44)
Creating and Using Instances
37(2)
Using Existing Classes
39(16)
Memory Management: Retain Count, Releasing, and Retaining
46(2)
Sending Messages to nil
48(1)
NSObject, NSArray, NSMutableArray, and NSString
49(5)
"Inherits from" Versus "Uses" or "Knows About"
54(1)
Creating Your Own Classes
55(19)
Creating the LotteryEntry Class
56(4)
Changing main.m
60(2)
Implementing a description Method
62(9)
Writing Initializers
71(1)
Initializers with Arguments
72(2)
The Debugger
74(4)
What Have You Done?
78(1)
For the More Curious: How Does Messaging Work?
78(2)
Challenge
80(1)
Chapter 4 Controls 81(22)
Some Commonly Used Subclasses of NSControl
83(4)
NSButton
84(1)
NSSlider
85(1)
NSTextField
86(1)
Start the SpeakLine Example
87(2)
Lay Out the Nib File
89(5)
Making Connections in Interface Builder
91(3)
Implementing the AppController Class
94(5)
Extending an Existing User Interface
96(3)
For the More Curious: Setting the Target Progranunatically
99(1)
Challenge
100(3)
Chapter 5 Helper Objects 103(18)
Delegates
104(4)
The NSTableView and Its dataSource
108(2)
AppController Interface File
109(1)
Lay Out the User Interface
110(2)
Make Connections
112(2)
Edit AppController.m
114(3)
Common Errors in Implementing a Delegate
116(1)
Many Objects Have Delegates
117(1)
Retain Cycles
117(1)
For the More Curious: How Delegates Work
117(2)
Challenge
119(2)
Chapter 6 Bindings and NSController 121(18)
Starting the RaiseMan Application
122(9)
Key-Value Coding
126(1)
In Interface Builder
127(4)
Key-Value Coding and nil
131(1)
Add Sorting
132(1)
For the More Curious: Sorting Without NSArrayController
133(1)
For the More Curious: Key Paths
134(1)
Challenge 1
135(1)
Challenge 2
135(4)
Chapter 7 NSUndoManager 139(12)
NSlnvocation
139(1)
How the NSUndoManager Works
140(3)
Adding Undo to RaiseMan
143(3)
Key-Value Observing
146(1)
Undo for Edits
147(2)
For the More Curious: Windows and the Undo Manager
149(2)
Chapter 8 Archiving 151(16)
NSCoder and NSCoding
152(3)
Encoding
153(1)
Decoding
154(1)
The Document Architecture
155(4)
Info.plist and NSDocumentController
156(1)
NSDocument
156(2)
NSWindowController
158(1)
Saving and NSKeyedArchiver
159(1)
Loading and NSKeyedUnarchiver
160(1)
Setting the Extension and Icon for the File Type
161(2)
For the More Curious: Preventing Infinite Loops
163(1)
For the More Curious: Versioning
164(2)
For the More Curious: Creating a Protocol
166(1)
For the More Curious: Document-Based Applications Without Undo
166(1)
Chapter 9 Nib Files and NSWindowController 167(16)
NSPanel
167(1)
Adding a Panel to the Application
168(12)
MainMenu.nib
169(1)
Setting Up the Menu Item
170(2)
AppController.m
172(1)
Preferences.nib
173(5)
PreferenceController.m
178(2)
For the More Curious: NSBundle
180(1)
Challenge 1
181(1)
Challenge 2
181(2)
Chapter 10 User Defaults 183(12)
NSDictionary and NSMutableDictionary
184(2)
NSDictionary
184(1)
NSMutableDictionary
185(1)
NSUserDefaults
186(1)
Precedence of Different Types of Defaults
187(1)
Setting the Identifier for the Application
188(1)
Creating Keys for the Names of the Defaults
188(1)
Registering Defaults
189(1)
Let the User Edit the Defaults
189(2)
Using the Defaults
191(3)
Suppressing the Creation of Untitled Documents
191(1)
Setting the Background Color on the Table View
192(2)
For the More Curious: Reading and Writing Defaults from the Command Line
194(1)
Challenge
194(1)
Chapter 11 Using Notifications 195(8)
What Notifications Are
195(1)
What Notifications Are Not
196(1)
NSNotification
196(1)
NSNotificationCenter
196(3)
Posting a Notification
199(1)
Registering as an Observer
199(1)
Unregistering the Observer
200(1)
Handling the Notification When It Arrives
200(1)
For the More Curious: Delegates and Notifications
201(1)
For the More Curious: The userInfo Dictionary
201(1)
Challenge 1
202(1)
Challenge 2
202(1)
Chapter 12 Using Alert Panels 203(4)
Make the User Confirm the Deletion
204(2)
Challenge
206(1)
Chapter 13 Localization 207(10)
Localizing a Nib File
208(2)
String Tables
210(4)
Creating String Tables
211(2)
Using the String Table
213(1)
For the More Curious: nibtool
214(1)
For the More Curious: Explicit Ordering of Tokens in Format Strings
215(2)
Chapter 14 Custom Views 217(16)
The View Hierarchy
217(2)
Get a View to Draw Itself
219(6)
Create an Instance of a View Subclass
221(1)
Size Info
222(1)
drawRect
223(2)
Drawing with NSBezierPath
225(2)
NSScrollView
227(2)
For the More Curious: Cells
229(2)
For the More Curious: isFlipped
231(1)
Challenge
232(1)
Chapter 15 Images and Mouse Events 233(16)
NSResponder
233(1)
NSEvent
233(2)
Getting Mouse Events
235(1)
Using NSOpenPanel
235(7)
Change the Nib File
237(3)
awakeFromNib Versus init
240(1)
Edit the Code
240(2)
Composite an Image onto Your View
242(2)
The View's Coordinate System
244(2)
Autoscrolling
246(1)
For the More Curious: NSlmage
247(1)
Challenge
248(1)
Chapter 16 Responders and Keyboard Events 249(16)
NSResponder
251(1)
NSEvent
251(1)
Create a New Project with a Custom View
252(9)
Edit the Nib File
252(5)
Write the Code
257(4)
For the More Curious: Rollovers
261(4)
Chapter 17 Working with Fonts and NSAttributedString 265(10)
NSFont
265(1)
Commonly Used Methods in NSFont
265(1)
NSAttributedString
266(2)
Drawing Strings and Attributed Strings
268(1)
Making Letters Appear
269(2)
Getting Your View to Generate PDF Data
271(3)
For the More Curious: NSFontlVlanager
274(1)
Challenge 1
274(1)
Challenge 2
274(1)
Chapter 18 Pasteboards and Nil-Targeted Actions 275(10)
NSPasteboard
276(1)
Add Cut, Copy, and Paste to BigLettcrVicww
277(2)
Nil-Targeted Actions
279(3)
Looking at the Nib File
281(1)
For the More Curious: Which Object Really Sends the Action Message?
282(1)
For the More Curious: Lazy Copying
282(1)
Challenge
283(2)
Chapter 19 Categories 285(4)
Add a Method to NSString
285(3)
For the More Curious: Declaring Private Methods
288(1)
Chapter 20 Drag-and-Drop 289(8)
Make BigLetterView Be a Drag Source
290(3)
After the Drop
292(1)
Make BigLetterView Be a Drag Destination
293(4)
registerForDraggedTypes
293(1)
Add Highlighting
294(1)
Implement the Dragging Destination Methods
295(1)
Testing
296(1)
Chapter 21 NSTimer 297(8)
Lay Out the Interface
298(2)
Make Connections
300(2)
Adding Code to AppController
302(2)
For the More Curious: NSRunLoop
304(1)
Challenge
304(1)
Chapter 22 Sheets 305(12)
Adding a Sheet
306(6)
Add Outlets and Actions
307(1)
Lay Out the Interface
307(3)
Add Code
310(2)
For the More Curious: contextInfo
312(1)
For the More Curious: Modal Windows
312(1)
For the More Curious: Alert Sheets
313(1)
For the More Curious: NSIDr.nv cr
313(2)
Challenge
315(2)
Chapter 23 Creating NSFormatlers 317(14)
A Basic Formatter
318(7)
Edit the Interface File for the AppController Class
319(1)
Edit the Nib File
320(1)
NSColorList
320(1)
Searching Strings for Substrings
321(1)
Create a Subclass of NSFormatter
322(3)
The Delegate of the NSControl
325(1)
Checking Partial Strings
326(2)
Formatters That Return Attributed Strings
328(1)
Challenge
329(2)
Chapter 24 Printing 331(12)
Adding Printing to TypingTutor
331(2)
Dealing with Pagination
333(6)
For the More Curious: Am I Drawing to the Screen?
339(1)
Using ObjectAlloc
339(2)
Challenge
341(2)
Chapter 25 Updating Menus 343(8)
Making a BigLetterView Uncopyable
344(3)
For the More Curious: Menu Delegates
347(4)
Chapter 26 Working with NSTextView 351(18)
NSTextView
351(2)
Messages the Delegate Will Be Sent
353(1)
Build the Editor with Which This Book Was Written
354(11)
Read, Write, and Edit Text Files
354(4)
Add a Context-Sensitive Menu
358(6)
Replace the Selection
364(1)
For the More Curious: The Field Editor
365(2)
Challenge
367(2)
Chapter 27 Creating Interface Builder Palettes 369(20)
Add NSCoding Methods to BigLetterView
371(1)
Create a Palette Project
372(1)
Edit the Nib File for Your Palette
373(2)
palette.table
375(1)
Build and Test
376(1)
finishInstantiate
376(2)
Adding an Inspector
378(7)
Create a Nib File for Your Inspector
379(5)
Code for an Inspector
384(1)
Adding Bindings to a Custom View
385(2)
For the More Curious: How to Palettize Objects That Are Not Views
387(1)
Challenge
388(1)
Chapter 28 AppleScript 389(10)
Making an Application AppleScript-able
390(2)
Create the Plists
392(3)
Handling the Apple Events
395(4)
Chapter 29 Cocoa and OpenGL 399(8)
A Simple Cocoa/OpenGL Application
400(7)
Chapter 30 Creating Frameworks 407(10)
Create a Framework
408(3)
Embed the Framework in an Application
411(3)
Compile the Framework for Embedding
411(1)
Compile the Application with the Framework
412(2)
Prebinding
414(1)
Zero-Link
415(2)
Chapter 31 GNUstep 417(10)
Creating a System That Will Run GNUstep Applications
418(1)
Building and Starting the Development Tools
419(1)
Creating the RandomApp with GNUstep
420(7)
Chapter 32 The End 427(2)
Index 429

Excerpts

Preface to the Second Edition I once studied with a wise mathematician named Soo Bong Chae. Dr. Chae had written a few really good books, and one day he told me his secret: "After I write a book, I put it away for two years. After avoiding the book for two years, I read it and rewrite the parts that need work. Then I publish it." The idea was a good one: By ignoring the book for two years, he could revise it with fresh eyes. But that's not what happened in my case. It has, indeed, been two years since I wrote the first edition of Cocoa(R) Programming for Mac(R) OS X. In that time, however, I have taught 20 classes using the book as a text. Overall, the first edition was a good book, but it was far from perfect. Where the book was weak, I have suffered. It was with great relish I eliminated these sore spots from this edition. During these two years, Apple has continued innovating upon the strong base that Mac OS X created. Hundreds of tiny improvements were made, and two large changes occurred: Project Builder was replaced by Xcode, and Cocoa bindings were added to Cocoa. Throughout this book, you will use Xcode, and Cocoa bindings are covered in Chapter 6. Also, during these years, I continued my work as a programmer. As my clients asked for certain features to be added to their products, I came to realize that several topics needed to be addressed in a new edition the book. Besides many new "For the More Curious" sections, the second edition has five entirely new chapters: Chapter 7 describes how to add undo capabilities to an application using NSUndoManager. Chapter 28 demonstrates how to make an application AppleScript-able. Chapter 29 shows how you can use OpenGL calls within a Cocoa application. Chapter 30 gives the necessary steps to create a reusable framework. Chapter 31 will get you started creating Cocoa applications on Linux using GNUstep. The final improvement is a physical one: The second edition has a lay-flat binding so that it can sit at your elbow as you work through the book. Although a subtle change, I think it will make your experience with the book and its ideas a little bit more pleasant. I don't get to ignore this book after it has been publishedthe quality of the book has a direct influence on the quality of the courses I teach. Is it a good book? Let me put it this way: I am looking forward to going through it with my students a dozen times this year. I guess that says something. Preface to the First Edition Cocoa is a powerful collection of tools and libraries that enable developers to write applications for Mac OS X. iPhoto, iChat, iCal, iSync and Safari were all written using Cocoa. Why Cocoa? Because it allows programmers to develop full-featured applications faster than ever before. The increased speed does not, however, come for free. The new technologies have a steep learning curve. This book will guide you through the ideas and techniques that separate the great Cocoa programmers from the wanna-be's. This book is written for programmers who already know some C programming and something about objects. The reader is not expected to have any experience with Mac programming. It is a hands-on book and assumes that the reader has access to Mac OS X and the developer tools. The developer tools are free. If you bought a shrink-wrapped copy of Mac OS X, the developer tools CD was in the box. The tools can also be downloaded from the Apple Developer Connection Web site ( http://connect.apple.com/ ). Aaron Hillegass 0321213149P04152004

An electronic version of this book is available through VitalSource.

This book is viewable on PC, Mac, iPhone, iPad, iPod Touch, and most smartphones.

By purchasing, you will be able to view this book online, as well as download it, for the chosen number of days.

Digital License

You are licensing a digital product for a set duration. Durations are set forth in the product description, with "Lifetime" typically meaning five (5) years of online access and permanent download to a supported device. All licenses are non-transferable.

More details can be found here.

A downloadable version of this book is available through the eCampus Reader or compatible Adobe readers.

Applications are available on iOS, Android, PC, Mac, and Windows Mobile platforms.

Please view the compatibility matrix prior to purchase.