- Copyright 2002
- Edition: 1st
-
Book
- ISBN-10: 0-201-72683-1
- ISBN-13: 978-0-201-72683-1
The practical guide everyone says you need!
"The most comprehensive guide to developing Cocoa available. For the developer new to Cocoa, it provides an excellent introduction that will lead to success with the world's best object-oriented development tools. For those familiar with Cocoa, the excellent organization and presentation make the book invaluable as a reference tool."
--Bill Bumgarner, Cofounder, CodeFab
With the arrival of Mac OS X, Apple now has a modern operating system that calls for advanced programming capability. To take full advantage of the exciting and innovative features of OS X, Apple recommends a development framework known as Cocoa. Cocoa is a powerful collection of object-oriented tools and libraries that makes developing applications a much faster process. Mastery of Cocoa is absolutely essential for anyone doing serious development work for the Macintosh.
"Mac OS X and Cocoa are going to revolutionize the world of software development in the coming years... Aaron Hillegass's book is without a doubt the best aid to learning this technology."
--Erik J. Barzeski, Editor, CocoaDevCentral.com
New technologies often have a steep learning curve and do not always come with complete instructions on how to get started or how to overcome common obstacles. Enter Cocoa(R) Programming for Mac(R) OS X, which shows you precisely how to put Cocoa to work.
"Reading this book is the absolute best way to learn how to harness the power of this amazing technology."
--Andrew Stone, President, Stone Design, www.stone.com
Guiding programmers through the key features of Cocoa, this book emphasizes design patterns that enable you to predict the behavior of classes you have never used before. Using a tutorial format, it takes you, step-by-step, through five applications and an InterfaceBuilder palette. Each project introduces several new ideas, and as each concept or technique is discussed, the author, drawing on his own extensive experience, shows you the advantages of working with Cocoa in object-oriented software development environments.
0201726831B11262001
Online Sample Chapter
Cocoa® Programming for Mac® OS X: Custom Views
Downloadable Sample Chapter
Click below for Sample Chapter related to this title:
hillegassch12.pdf
Table of Contents
Acknowledgments.
1. Cocoa: What Is It?
A Little History.
Tools.
Objects, Classes, Methods, and Messages.
Frameworks.
How to Read this Book.
Typographical Conventions.
How to Learn.
2. Let's Get Started. In Project Builder.
In Interface Builder.
Back in Project Builder.
Documentation.
What Have You Done?
3. Objective-C. Creating and Using Instances.
Using Existing Classes.
Creating Your Own Classes.
The Debugger.
What Have You Done?
For the More Curious: How Does Messaging Work?
Challenge.
4. Controls. Some Commonly Used Subclasses of NSControl.
Start the RaiseMan Example.
The Interface File for MyDocument.
Layout the Interface.
Implementing the Person Class.
Implementing the MyDocument Class.
What Have You Done?
For the More Curious: Setting the Target Programmatically.
Challenge.
5. Helper Objects. NSTableView and Its Data Source.
MyDocument Interface File.
Layout the User Interface.
Make Connections.
Edit MyDocument.m.
Key-value Coding.
Delegates.
For the More Curious: How Delegates Work.
Challenge 1.
Challenge 2.
6. Archiving. NSCoder and NSCoding.
The Document Architecture.
Saving and NSArchiver.
Loading and NSUnarchiver.
Informing the Document That It Has Been Edited.
Setting the Extension and Icon for the File Type.
For the More Curious: Preventing Infinite Loops.
For the More Curious: Versioning.
For the More Curious: Creating a Protocol.
7. Nib Files and NSWindowController. NSPanel.
Adding a Panel to the Application.
For the More Curious: NSBundle.
Challenge 1.
Challenge 2.
8. User Defaults. NSDictionary and NSMutableDictionary.
NSUserDefaults.
Creating Keys for the Names of the Defaults.
Registering Defaults.
Let the User Edit the Defaults.
Using the Defaults.
Saving the Frame of a Window.
For the More Curious: Reading and Writing Defaults from the Command-line.
Challenge.
9. Using Notifications. What Notifications Are.
What Notifications Are Not.
NSNotification.
NSNotificationCenter.
Posting a Notification.
Registering as an Observer.
Unregistering the Observer.
Handling the Notification When It Arrives.
For the More Curious: Delegates and Notifications.
For the More Curious: The userInfo Dictionary.
Challenge.
10. Using Alert Panels. Make the User Confirm the Delete.
Challenge.
11. Localization. Localizing a Nib File.
String Tables.
For the More Curious: nibtool.
Challenge.
12. Custom Views. The View Hierarchy.
Get a View to Draw Itself.
Drawing with NSBezierPath.
NSScrollView.
For the More Curious: Cells.
Challenge 1.
13. Images and Mouse Events. NSResponder.
NSEvent.
Getting Mouse Events.
Using NSOpenPanel.
Composite an Image Onto Your View.
The View's Coordinate System.
Autoscrolling.
For the More Curious: NSImage.
Challenge.
14. Responders and Keyboard Events. NSResponder.
NSEvent.
Create a New Project with a Custom View.
15. Working with Fonts and NSString. NSFont.
NSAttributedString.
Drawing Strings and Attributed Strings.
Making Letters Appear.
Getting Your View to Generate PDF Data.
For the More Curious: NSFontManager.
Challenge 1.
Challenge 2.
16. Pasteboards and Nil-targeted actions. NSPasteboard.
Add Cut, Copy, and Paste to BigLetterView.
Nil-targeted Actions.
For the More Curious: Which Object Really Sends the Action Message?
For the More Curious: Lazy Copying.
Challenge.
17. Categories. Add a Method to NSString.
18. Drag and Drop. Make BigLetterView a Drag Source.
Make a BigLetterView a Drag Destination.
Challenge.
19. NSTimer. Layout the Interface.
Make Connections.
Adding Code to AppController.
Challenge.
20. Sheets. Adding a Sheet.
For the More Curious: contextInfo.
For the More Curious: NSDrawer.
Challenge.
21. Creating NSFormatters. A Basic Formatter.
The Delegate of the NSControl.
Checking Partial Strings.
The Control's Delegate and Partial Strings.
Formatters that Return Attributed Strings.
Challenge.
22. Printing. Adding Printing to TypingTutor.
Dealing with Pagination.
Challenge.
23. Updating Menu_n. Making a BigLetterView Uncopyable.
24. Working with NSTextView. NSTextView.
Messages the Delegate Will Be Sent.
Build the Editor With Which This Book Was Written.
For the More Curious: The Field Editor.
25. Using Java with Cocoa. Don't Use Java to Write Cocoa Applications.
If You Must Use Java to Write Cocoa Applications.
26. Creating Interface Builder Palettes. Add NSCoding Methods to BigLetterView.
Create a Palette Project.
Edit the Nib File for Your Palette.
palette.table.
Build and Test.
FinishInstantiate.
Adding an Inspector.
For the More Curious: How to Palettize Objects That Are Not Views.
Challenge.
27. The End. Index. 0201726831T10152001
Preface
With the arrival of Mac OS X, Apple recommends that all new applications be written using Cocoa. Cocoa is a powerful collection of tools and libraries that will make writing new programs a much faster process.
The increased speed does not, however, come for free. The new technologies have a steep learning curve, and Apple's documentation leaves much to be desired. This book will guide you through the ideas and techniques that separate the great Cocoa programmers from the wanna-bes.
This book is written for programmers who already know C++ or Java and are curious about Cocoa. 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.
0201726831P10152001
Index
Symbols
- @.".." Construct, 48
- %@ Token, 39, 44
A
- Abstract classes, 122
- acceptsFirstResponder, 224, 225
- Accessor methods, 52, 59-61, 114
- Action(s), 18, 19, 83-85
- of buttons, 89
- of controls, 73-74
- nil-targeted, 251-54
- responder chain to, 251, 252, 253
- Action message, source of, 254
- Active view, 223
- addObject:, 34, 47, 71
- addObjectsFromArray:, 47
- addObserver:selector:name:object:, 169
- Alert panels, 175-79
- confirming deletion, 176-78
- NSRunAlertPanel(), 175-76
- allKeys, 157
- alloc, 44
- AppKit (ApplicationKit) framework, 6, 73
- Apple Computer, 1, 2, 3
- Application(s), 10
- chronology of, 31, 32
- defaults for, 160
- document-based, 88
- drawing, 205
- main bundle of, 152-53
- names of, 11
- notifications between, 168
- applicationShouldOpenUntitledFile:, 163
- archivedDataWithRootObject:, 129
- Archiving, 121-37
- defined, 121
- document architecture, 125-28
- NSDocument, 125, 126-28
- NSDocumentController, 125-26
- NSWindowController, 125, 128
- edited documents, recognizing, 130-31
- file extensions, 131-34
- infinite loop prevention in, 134-35
- NSArchiver, 122, 128-29, 134-35
- NSCoding and NSCoder, 122-25
- NSUnarchiver, 122, 129-30, 134
- parts of, 121-22
- protocol creation, 136-37
- versioning, 135-36
- Arguments
- from command line, 160
- initializers with, 66-67
- methods with, 34-35
- Array(s)
- memory management of, 42
- of objects, 38-39
- aSelector, 118
- aString, 291
- Attributed strings, 238-40
- returned by formatter, 302
- Attributes, dictionary of, 240
- autorelease, 60
- Autoreleased objects, 56-59
- "Autorelease Old Value" setter method, 60
- Autorelease pools, 38
- autoscroll:, 220
- Autoscrolling, 219-20
- timer driven, 276-77
- availableTypeFromArray:, 249
- awakeFromNib, 29-30, 87, 298
- init vs., 212-13
B
- Background color, 164-65
- becomeFirstResponder, 224, 225
- beginSheet:modalForWindow:modalDelegate:
didEndSelector:contextInfo:, 279 - beginSheetForDirectory:file:modalForWindow:
modalDelegate:didEndSelector:
contextInfo:,*215 - Berners-Lee, Tim, 3
- Blank window, 15
- BOOL, 26
- boolForKey:, 159
- Breakpoints, 67-69
- BSD Unix, 1
- Building applications, 28-29
- Bundle(s), 152-53
- palettes as, 350
- Bundle project, 10
- Button(s). See also NSControl
- attributed strings in, 239
- radio, 78
- target and action of, 89
C
- C, 33
- strings in, 39
- C++, 2-3, 33
- method implementation in, 27
- calendarDate, 61-62
- Calendar format string, tokens in, 64
- Categories, 257-60
- defined, 257
- for NSString, 257-60
- Cells, 201-4
- Centering text, 16-17
- changeColor:, 162
- changeNewEmptyDoc:, 162
- char*, NSString vs., 39
- characters, 226
- "Check Before Change" setter method, 60
- Chronology of an application, 31, 32
- Class(es), 4-5, 35-40. See also specific classes
- abstract, 122
- in AppKit Foundation, 6-7
- archiving names of, 121
- creating, 49-67
- declaration of
- in Java, 24-25
- in Objective-C, 25, 27
- groups of, 100
- naming conventions for, 7, 18, 43
- notification sent by, 167
- Classes, 24
- Class method, 62
- Class structure, 71
- Cleaning projects, 133
- clickCount, 207
- Cocoa, 1-8
- frameworks in, 5-6
- history of, 1-3
- object-oriented concepts in, 4-5
- resources on, 369-70
- tools for, 3-4
- Color, background, 164-65
- Color objects, 302-3
- dictionary of, 294
- colorSpaceName, 303
- colorUsingColorSpaceName:, 303
- Color well, 152
- com.apple.cocoa.foundation.
NSGregorianDate,*347 - Command line, defaults from, 160, 165-66
- Compiling, 29
- Composition, 48-49
- concludeDragOperation:, 264
- Conditional encoding, 134-35
- Console, 68
- Constants in Objective-C, 26
- containsObject:, 46
- Content view, 189
- contextInfo parameter, 286-87
- Context-sensitive menu, 329-37
- Control(s), 73-102
- NSControl, 74-79, 201
- ancestors of, 74
- delegate of, 299-300, 339
- subclasses of, 73, 75-79
- RaiseMan application, 79-101
- formatter for, 87-88
- interface file for MyDocument, 81-83
- interface layout, 83-84
- MyDocument class implementation, 96-99
- Person class implementation, 94-96
- setting target programmatically, 101
- target and action of, 73-74
- control:didFailToFormatString:
errorDescription:, 299 - Control-dragging, 22, 90
- Controller classes, 100
- Copeland Project, 3
- Copying
- lazy, 254-55
- with pasteboard, 249-51
- count, 46, 157
- Cox, Brad, 33
- currentRect, 219
- Custom views, 189-204, 226-36
- cells and, 201-4
- code for, 232-36
- connections, 230-32
- creating, 191-97
- drawRect:, 194-97
- instance of new subclass, 193-94
- interface layout, 229, 231
- nib file for, 226-28
- NSBezierPath, 196, 197-99
- NSScrollView, 199-201
- NSView, 189, 201
- size info, 194, 230
- Cutting with pasteboard, 249-51
D
- Darwin source code, 2
- dataForType:, 249
- dataRepresentationOfType:, 126-27, 129
- dataSource, 105-6, 109, 110
- dataWithPDFInsideRect:, 243
- dateByAddingYears:months:days:hours:minutes:
seconds:, 62 - dateWithYear:month:day:hour:minute:second:
timeZone:, 62 - dayOfCommonEra, 63
- dayOfMonth, 63
- dayOfWeek, 63
- dayOfYear, 63
- dealloc, 44-45, 53, 172
- image released with, 216
- Debugger (gdb), 4, 67-70
- declareTypes:owner:, 248
- decodeObject, 124
- decodeValueOfObjCType:at:, 124
- defaultCenter, 169
- Defaults
- from command line, 160, 165-66
- precedence of different types of, 160
- registering, 158, 161
- setting, 158, 159
- user, 155-66
- creating keys for names of, 160-61
- editing, 161-62
- NSUserDefaults, 155, 158-60
- preferences panel with, 158, 161-65
- reading and using, 158
- saving frame of window, 165
- using, 163-65
- Delegate(s), 115-19
- creating, 163
- implementation errors, 117
- notifications and, 173
- of NSControl, 299-300, 339
- of NSTextView, 323-24
- objects with, 117-18
- operation of, 118-19
- partial strings and, 301
- retention of, 118
- delegate, nil-targeted action and, 252
- deltaX, 207
- deltaY, 207
- deltaZ, 207
- descender, 238
- description, 44, 55-64
- accessor methods, 59-61
- autoreleased objects, 56-59
- NSCalendarDate, 61-67
- overriding, 56
- Designated initializer, 67, 125
- dictionary, 158
- Dictionary, 155, 157
- of attributes, 240
- of color objects, 294
- userInfo, 173-74
- didEnd:returnCode:contextInfo:, 243
- Directory
- MacOS/, 134
- project, 9, 11
- Resources/, 134
- dissolveToPoint:fraction:, 216
- DocBook, 324, 332
- Document(s). See also Archiving
- architecture of, 125-28
- NSDocument, 125, 126-28
- Document(s), continued
- NSDocumentController, 125-26
- NSWindowController, 125, 128
- recognizing edited, 130-31
- untitled, suppressing creation of, 163-64
- Documentation, 30, 31
- online, 369
- Document-based applications, 88
- Document type definition (DTD), 324
- Document window, 17-18
- class browser in, 18
- Drag-and-drop, 261-68
- destination of, 264-68
- highlighting for, 265
- implementing methods, 266-67
- registerForDraggedTypes:, 264-65
- source of, 261-64
- to table view, 268
- draggingEntered:, 264
- draggingExited:, 264
- Dragging pasteboard, 261
- draggingSourceOperationMaskForLocal:, 262
- draggingUpdated:, 264
- dragImage:at:offset:event:pasteboard:source:
slideBack:, 262 - drawAtPoint:, 240
- drawAtPoint:withAttributes:, 240
- Drawers, 287-89
- Drawing application, 205
- Drawing strings, 240
- drawInRect:, 240
- drawInRect:withAttributes:, 240
- drawRect:, 194-97, 216, 219, 243
- adding highlighting to, 265
- DTD (document type definition), 324
E
- Edited documents, recognizing, 130-31
- Editor, 324-39
- context-sensitive menu, 329-37
- field editor, 337-39
- reading, writing, and editing text files, 324-29
- @encode compiler directive, 123
- encodeConditionalObject:, 134
- encodeObject:, 123
- encodeValueOfObjCType:at:, 123
- encodeWithCoder:, 122, 123, 124, 350, 367
- Encoding, conditional, 134-35. See also Archiving
- endSpeedWindow:, 286
- Enumerators (iterators, enumerations), 157
- Equality, idea of, 45
- errorPtr, 291
- Event(s)
- keyboard, 223
- in custom view, 232-36
- NSEvent, 226
- mouse, 205-7, 217-19
- getting, 207
- modifier keys and, 206
- NSEvent, 205-7, 226
- NSResponder, 205
- Event-handling methods, 205
- Extensions, file, 131-34
F
- Field editor, 337-39
- File extensions, 131-34
- File type, icon for, 131-34
- File wrapper, 126
- fileWrapperRepresentationOfType:, 127
- finishInstantiate, 357, 367
- First Responder, 17-18
- menu updates and, 315, 316
- firstResponder, 223-24
- nil-targeted action and, 252
- First-responder status, 232
- flagsChanged:, 225
- floatForKey:, 159
- float type, 114
- floatValue, 77
- Fonts, 237-45
- making letters appear, 241-43
- NSAttributedString, 238-40
- drawing with, 240
- NSFont, 237-38
- NSFontManager, 245
- fontWithName:size:, 237-38
- Foreign language, localizing for, 179-85
- Formatter, 87-88, 291. See also NSFormatter
- attributed strings returned by, 302
- interface file for, 293-94
- nib file for, 294
- NSColorList, 294
- number, 107-8
- partial strings, 300-301
- for RaiseMan application, 87-88
- connections for, 88-93
- main menu, 94
- searching strings for substrings, 295-96
- Foundation classes, 100
- Foundation framework, 6
- Foundation tool, 35-40
- Framework project, 10
- Frameworks, 2, 5-6
- AppKit, 6, 73
- Free Software Foundation, 67
G
- generalPasteboard, 248
- getObjectValue:forString:errorDescription:, 291
- "get" prefix, 60-61
- Getter methods, 60-61
- Global defaults, 160
- Global variables, 160-61
- for standard pasteboards, 248-49
- GNU C compiler (gcc), 4
- GNU debugger (gdb), 4, 67-70
- Graph of objects, 121
H
- handleColorChange:, 172
- Header file (interface file), 19
- Helper objects, 103-20. See also Delegate(s)
- hidesOnDeactivate (boolean variable), 140
- hourOfDay, 63
I
- IBAction, 26, 28
- IBOutlet macro, 26
- .icns file, 131
- Icon for file type, 131-34
- identifier instance variable, 108
- Id pointer, 26
- Images, 205-21
- locating and dimensioning, 217-19
- NSImage, 220
- NSOpenPanel, 207-8
- on view, 215-17, 219-20
- Immutability, 46
- Implementation file, 19
- import, 27, 160
- indexOfObject:, 46
- Info.plist, 125-26, 134
- Info panel, 16, 86. See also Inspectors
- Inheritance, 48-49
- init, 34, 44, 67, 172
- awakeFromNib vs., 212-13
- initialFirstResponder, 92, 93
- initialize, 136
- Initializer(s), 64-67
- with arguments, 66-67
- designated, 67, 125
- initWithCoder:, 122, 124-25, 350, 367
- initWithEntryDate:, 67
- initWithFormat:, 48
- initWithFrame:, 198, 212, 309, 311, 350
- initWithRect:, 264
- insertObject:, 47
- Inspectors, 16
- for palettes, 349-50, 358-65
- code for, 361-65
- nib files for, 359-61
- role of, 364
- Instances, 5
- creating and using, 33-35
- Instance variables, 4-5, 18
- accessor methods for, 59-61
- archiving of, 121
- declaration of, 26-27
- naming convention for, 19
- integerForKey:, 159
- Intelligence community, 3
- @Interface, 27
- Interface Builder, 3, 4, 13
- palettes in. See Palettes
- Interface file (header file), 19
- "IOU" on pasteboard, 254-55
- isa instance variable, 71
- isARepeat, 226
- isEqual:, 45
- Iterators, 157
J
- Java, 4, 341-48
- class declaration in, 24-25
- interface construct, 122
- messages to nil in, 42
- method implementation in, 27
- RandomApp application in, 342-48
- connections, 344-46
- documentation, 348
- interface layout, 342-43
- Java, continued
- subclassing Cocoa classes in, 347-48
- java.util.date, 347
- Java Bridge, 341
- Jobs, Steve, 1
K
- Keyboard events, 223
- in custom view, 232-36
- NSEvent, 226
- keyCode, 226
- keyDown, 224
- keyEnumerator, 157
- keyUp:, 225
- Key-value coding, 113-15
- Key views, 230
- Key window, 223
L
- Language defaults, 160
- lastObject, 46
- laterDate:, 63
- Lazy copying, 254-55
- length, 48
- Library of code, 5
- Literals, 7
- loadDataRepresentation:ofType:, 127, 129-30
- loadFileWrapperRepresentation:ofType:, 127
- Loading documents, 127-30
- Localization, 153, 179-87
- for foreign language, 179-85
- of nib file, 180-81, 185-86
- nibtool, 185-86
- NSBundle, 179
- string tables and, 182-85
- creating, 182-85
- using, 185
- Local variables, 53
- locationInWindow, 206
- Locks focus, 196
- Loop
- infinite, 134-35
- main event, 31
- LotteryEntry (custom class), 49-67
- dealloc method, 53
- description, 55-64
- accessor methods, 59-61
- autoreleased objects, 56-59
- NSCalendarDate, 61-67
- overriding, 56
- header file for, 49-52
- implementation file for, 52-53
- initializers, 64-67
- main.m, 59
M
- Mach microkernel, 1
- MacOS/ directory, 134
- Mac OS X, 2, 3, 305
- Mailing lists, Cocoa-related, 370
- main, 37
- main.m of a foundation tool, 36-38
- Main bundle of application, 152-53
- Main event loop, 31
- MainMenu.nib, 13, 88, 94, 139
- Main window, 252
- Memory leak, 42, 56
- Menu(s)
- context-sensitive, 329-37
- updating, 315-19
- nil-targeted actions and, 315
- in Typing Tutor application, 316-19
- validateMenuItem and, 315
- menuForEvent:, 337
- Message(s), 4-5
- action, source of, 254
- in awakeFromNib vs. init, 212-13
- to freed object, 43
- to nil, 42-43
- messageFontOfSize:, 237
- Messaging, 71-72
- Method(s), 4-5, 18. See also specific methods
- with arguments, 34-35
- class, 62
- event-handling, 205
- getter, 60-61
- implementation of, 27-28
- naming conventions for, 7, 19
- for NSArray, 46
- for NSMutableArray, 47
- for NSObject, 43-45
- for NSString, 47-48
- with return values, 35
- setter, 59-60
- Microkernel approach, 1
- minuteOfHour, 63
- Modal operation, 176
- Model, 100
- Model-View-Controller design pattern,
100-101,*125 - modifierFlags, 206, 226
- Modifier keys with mouse events, 206
- Modularity, 140
- monthOfYear, 63
- mouseDown:, 205, 262
- mouseDragged:, 205, 218, 220, 262
- mouseEntered:, 205
- Mouse events, 205-7, 217-19
- getting, 207
- modifier keys and, 206
- NSEvent, 205-7
- NSResponder, 205
- mouseExited:, 205
- mouseMoved:, 205
- mouseUp:, 205, 218
- MyDocument.nib, 88, 139
N
- name, 168
- NeXT Computer, Inc., 1
- nextKeyView, 92, 93
- nextResponder instance variable, 251
- NeXT Software, Inc., 1, 2
- NeXTSTEP, 1, 3
- Nib file(s), 12-13, 16, 29, 139-54
- connections in, 90-92
- creating, 146
- for custom views, 226-28
- for document-based applications, 88
- File's Owner placeholder in, 147-48
- for formatter, 294
- invisible objects in, 17
- localization of, 180-81, 185-86
- objects in, 349
- for palettes, 350, 354
- inspectors, 359-61
- nibtool, 185-86
- nil
- initialization failure and, 65
- messages to, 42-43
- in NSArray, 46
- nil pointer, 26
- Nil-targeted actions, 251-54
- responder chain to, 251, 252, 253
- updating menus and, 315
- Notifications, 167-74
- between applications, 168
- classes sending, 167
- defined, 167-68
- delegates and, 173
- handling, 172-73
- NSNotification, 168
- NSNotificationCenter, 167, 168-70
- objects attached to, 168
- posting, 170-71
- registering for, 169-72
- unregistering observer for, 172
- userInfo dictionary and, 173-74
- NSApp (global variable), 31
- NSApplication, 18, 254
- nil-targeted action and, 252
- sheets created using, 279-80
- NSApplicationMain, 12, 31
- NSArchiver, 122, 128-29. See also Archiving
- infinite loop issue and, 134-35
- NSArray, 45-46, 332
- enumerators created by, 157
- methods used on, 46
- nil in, 46
- NSAttributedString, 238-40, 302
- drawing with, 240
- NSAutoreleasePool, 38, 56-57
- NSBezierPath, 196, 197-99
- NSBox, 189
- NSBrowser, 105
- NSBundle, 72, 152-53, 179
- NSButton, 73, 75-76, 201-3
- target and selector of, 269
- NSButtonCell, 202, 203
- NSCalendarDate, 29, 61-64, 79, 291
- NSClipView, 200
- NSCoder, 122-25, 134
- as abstract class, 122-25
- versioning methods, 135-36
- NSCoding, 122-25, 350-52
- NSColor, 303
- NSColorList, 294
- NSColorWell, 73, 203
- NSControl, 74-79, 201
- ancestors of, 74
- delegate of, 299-300, 339
- subclasses of, 73, 75-79
- NSControl, continued
- NSButton, 73, 75-76, 201-3, 269
- NSSlider, 73, 77, 203
- NSTextField, 78-79, 203
- NSData, 126-27, 128-29, 322
- NSDateFormatter, 79, 291, 292, 347
- NSDecimalNumber, 114
- NSDictionary, 155, 156, 157, 332
- NSDistributedNotificationCenter, 168
- NSDocument, 125, 126-28, 309
- nil-targeted action and, 252
- NSDocumentController, 125-26
- nil-targeted action and, 252
- NSDraggingInfo, 266
- NSDrawer, 287-89
- NSEvent, 205-7, 226
- NSFileWrapper, 127
- NSFont, 237-38
- NSFontManager, 245
- NSFormatter, 291-303
- methods of, 291-92
- subclass of, 296-99
- NSImage, 196, 220
- NSImageRep, 220
- NSLayoutManager, 321
- NSLog, 39
- NSMakeRange(), 238
- NSMatrix, 202, 203
- NSMutableArray, 33-34, 35, 47, 48
- methods used on, 47
- NSMutableAttributedString, 238, 321
- NSMutableDictionary, 155, 156, 158
- NSMutableString, 46
- NSNotification, 168
- NSNotificationCenter, 167, 168-70
- NSNumber, 38
- immutability of, 46
- NSNumberFormatter, 87, 291
- NSObject, 18, 43-45, 71, 74, 118
- designated initializer for, 67
- methods used on, 43-45
- NSOpenPanel, 207-8
- NSPanel, 139-40
- "NS" prefix, 43
- NSPrintInfo, 309
- NSProgressIndicator, 269, 271
- NSRange, 238, 295
- NSResponder, 74, 205, 224-25
- nil-targeted actions and, 251
- NSRunAlertPanel(), 175-76
- NSScrollView, 109, 190, 199-201
- NSSecureTextField, 79
- NSSlider, 73, 77, 203
- NSSliderCell, 203
- NSSplitView, 190
- NSString, 47-48, 240, 332
- adding method to, 257-60
- autoreleased objects in, 57
- char* vs., 39
- immutability of, 46
- methods used on, 47-48
- NSTableView
- dataSource helper object, 104-6
- methods used on, 116-17
- NSTableViewColumn, 108
- NSTabView, 190
- NSText, 321
- NSTextContainer, 321
- NSTextField, 78-79, 203
- NSTextFieldCell, 203
- NSTextStorage, 321
- NSTextView, 73, 78, 321-39
- delegate of, 323-24
- editor built using, 324-39
- context-sensitive menu, 329-37
- field editor, 337-39
- reading, writing, and editing text files, 324-29
- methods for, 322-23
- NSTimer, 269-77
- NSUnarchiver, 122, 129-30, 134
- NSUserDefaults, 155, 158-60
- NSView, 74, 189, 201, 264, 350
- PDF data generation with, 243
- NSWindow, 15, 189
- NSWindowController, 125, 128, 139-54, 165.
See also Preferences panel - nib file loaded by, 151
- nil-targeted action and, 252
- Number formatter, 107-8
- numberOfRowsInTableView:, 104
O
- objc_msgSend(), 72
- Object(s), 4-5
- object, 168
- Object(s)
- archiving of. See Archiving
- arrays of, 38-39
- attached to notifications, 168
- autoreleased, 56-59
- color, 302-3
- with delegates, 117-18
- destroying, 34
- graph of, 121
- helper, 103-20. See also Delegate(s)
- initializing, 34
- message to freed, 43
- in nib file, 349
- observer, 167
- poster, 167
- retain count of, 40-42
- temporary, 57-59
- objectAtIndex, 46
- objectEnumerator, 157
- objectForKey:, 155, 157, 159
- Objective-C, 2-3, 4, 33-72
- classes, 35-40. See also specific classes
- creating, 49-67
- declaration of, 25, 27
- "inherits from" vs. "uses" vs. "knows about" in, 48-49
- instances, 33-35
- memory management, 40-42
- messages to nil, 42-43
- messaging in, 71-72
- protocol construct, 122
- types and constants in, 26
- variable declaration in, 43
- Object-oriented concepts, 4-5
- Object-Oriented Programming and the Objective-C Language, 4
- objectValue, 79
- Observer, registering and unregistering, 171-72
- Observer objects, 167
- ok:, 360
- Old-school plist, 332
- Online documentation, 369
- openPanelDidEnd:returnCode:contextInfo:, 215
- OpenStep, 2, 3
- Outlets, 18, 19, 83-85
P
- Pagination, printing and, 307-13
- Palettes, 349-68
- archive/unarchive ability of, 349, 350
- building and testing, 356-57
- as bundle, 350
- creating project, 352-53
- finishInstantiate message, 357
- inspectors for, 349-50, 358-65
- code for, 361-65
- nib files for, 359-61
- role of, 364
- nib files for, 350, 354, 359-61
- NSCoding methods for, 350-52
- of objects that are not views, 365-67
- palette.table, 354-56
- standard, 15
- Palette window, 15
- Panel(s)
- alert, 175-79
- confirming deletion, 176-78
- NSRunAlertPanel(), 175-76
- creating, 148
- preferences. See Preferences panel
- windows vs., 139-40
- Pasteboard(s), 247-51
- cut, copy, and paste using, 249-51
- dragging, 261
- "IOU" on, 254-55
- lazy copying to, 254-55
- NSPasteboard, 247, 248-49
- types of, 247-49
- pasteboard:provideDataForType:, 255
- Pasteboard server, 247
- pasteboardWithName:, 248
- PDF (Portable Document Format), 2
- generated in view, 243-45
- performClose:, 251-52
- performDragOperation:, 264
- Plist (property list), 332-36
- Pointer(s), 5
- accessor methods for, 59-60
- declaring, 266-67
- id, 26
- nil, 26
- to object's class, 71
- setting by control-dragging objects, 23
- Poster objects, 167
- postNotification:, 170
- postNotificationName:object:, 170
- Preferences panel, 139-54
- Preferences panel, continued
- AppController code, 145
- editing MainMenu.nib, 140-42
- implementation file for, 151-52
- menu item setup, 142-44
- PreferenceController, 140, 142
- Preferences.nib file, 145-50
- with user defaults, 158, 161-65
- user interface layout, 148-50
- Prefixes
- "get," 60-61
- for global variables, 161
- "NS," 43
- prepareForDragOperation:, 264
- pressure, 207
- print:, 305-6
- printDocument:, 309
- printf, 39
- printInfo, 309
- Printing, 305-13
- pagination and, 307-13
- in RaiseMan application, 307-13
- in Typing Tutor application, 305-6
- "Print-object" ("po"), 68
- printShowingPrintPanel:, 305, 309
- Project(s)
- cleaning, 133
- skeleton of, 11-12
- types of, 9-10
- Project Builder, 3, 4, 9
- incremental builds by, 133
- Project directory, 9, 11
- Property list (plist), 332-36
- Protocols, 122
- creation of, 136-37
R
- Radio buttons, 78
- RaiseMan application, 79-101
- formatter for, 87-88
- connections for, 88-93
- main menu, 94
- helper objects in, 103-20
- connections, 109-11
- delegates, 115-19
- editing MyDocument.m, 111-13
- key-value coding, 113-15
- MyDocument as dataSource, 105-6, 109, 110
- user interface layout, 106-9
- interface file for MyDocument, 81-83
- interface layout, 83-84
- MyDocument class implementation, 96-99
- Person class implementation, 94-96
- preferences panel for, 139-54
- AppController code, 145
- editing MainMenu.nib, 140-42
- implementation file for, 151-52
- menu item setup, 142-44
- PreferenceController, 140, 142
- Preferences.nib file, 145-50
- user interface layout, 148-50
- printing in, 307-13
- setting target programmatically, 101
- Random number generator application, 9-32
- building and running, 28-29
- class creation, 18-21
- connecting objects, 21-24
- editing header file, 26-27
- editing implementation file, 27-28
- instance creation, 21
- interface layout, 16-17
- Java in, 342-48
- connections, 344-46
- documentation, 348
- interface layout, 342-43
- main function, 12-13, 14
- naming, 11
- new project creation, 9-12
- readFromFile:ofType:, 127
- registerDefaults:, 159
- Registered defaults, 160
- registerForDraggedTypes:, 264-65
- Registering defaults, 158, 161
- Registering for notifications, 169-72
- release, 34, 40-42, 44
- rules concerning, 57
- removeAllObjects, 47
- removeObject:, 47
- removeObjectAtIndex:, 47
- removeObjectForKey:, 158, 159
- removeObserver:, 170
- replaceCharactersInRange:withRTF:, 322
- replaceCharactersInRange:withRTFD:, 322
- replaceCharactersInRange:withString:, 322
- resignFirstResponder, 224, 225
- Resources/ directory, 134
- Resources on Cocoa, 369-70
- Responder chain, 251, 252, 253
- Responders
- firstResponder, 223-24, 252
- NSEvent, 205-7, 226
- NSResponder, 74, 205, 224-25, 251
- respondsToSelector:, 118-19
- retain, 40-42, 45
- "Retain, Then Release" setter method, 59-60
- Retain counts, 40-42, 118
- Retain cycles, 118
- Reuse, 100-101
- revert:, 360
- rightMouseDown:, 205
- rightMouseDragged:, 205
- rightMouseUp:, 205
- RTFDFromRange:, 322
- RTFD (Rich Text Format with attachments), 321
- RTFFromRange:, 322
- RTF (Rich Text Format), 321
- Running applications, 28-29
S
- Saving
- documents, 126-29
- frame of window, 165
- Scrollable radio button, 78
- ScrollRangeToVisible:, 323
- Scroll view, 109, 190
- scrollWheel:, 205
- Scroll wheel, position of, 207
- Sculley, John, 1
- Searching strings for substrings, 295-96
- Securities analysts, 3
- selectedRange, 322
- Selectors, 34-35, 71
- Selector table, 72
- self (local variable), 53
- SEL type, 71
- sendAction:to:from:, 254
- Serialization, 121
- setAction:, 101
- setBool:forKey:, 159
- setCalendarFormat:, 63
- setData:forType:, 249
- setEnabled:, 76
- setFloat:forKey:, 159
- setFloatValue:, 77
- SetFont:range:, 323
- setInteger:forKey:, 159
- setNeedsDisplay:, 196
- setNeedsDisplayInRect:, 196-97
- setObject:forKey:, 158, 159
- setObjectValue:, 79
- setSelectedRange:, 322
- setState:, 76
- setString:, 322
- setString:forType:, 249
- setStringValue:, 79
- Setter methods, 59-60
- SetTextColor:range:, 323
- Setting defaults, 158, 159
- setVersion:, 136