You are previewing Cocoa in a Nutshell.
O'Reilly logo
Cocoa in a Nutshell

Book Description

Cocoa® is more than just a collection of classes, and is certainly more than a simple framework. Cocoa is a complete API set, class library, framework, and development environment for building applications and tools to run on Mac OS® X. With over 240 classes, Cocoa is divided into two essential frameworks: Foundation and Application Kit. Above all else, Cocoa is a toolkit for creating Mac OS X application interfaces, and it provides access to all of the standard Aqua® interface components such as menus, toolbars, windows, buttons, to name a few. Cocoa in a Nutshell begins with a complete overview of Cocoa's object classes. It provides developers who may be experienced with other application toolkits the grounding they'll need to start developing Cocoa applications. Common programming tasks are described, and many chapters focus on the larger patterns in the frameworks so developers can understand the larger relationships between the classes in Cocoa, which is essential to using the framework effectively. Cocoa in a Nutshell is divided into two parts, with the first part providing a series of overview chapters that describe specific features of the Cocoa frameworks. Information you'll find in Part I includes:

  • An overview of the Objective-C language

  • Coverage of the Foundation and Application Kit frameworks

  • Overviews of Cocoa's drawing and text handling classes

  • Network services such as hosts, Rendezvous URL services, sockets, and file handling

  • Distributed notifications and distributed objects for interapplication communication

  • Extending Cocoa applications with other frameworks, including the AddressBook, DiscRecording, and Messaging frameworks

The second half of the book is a detailed quick reference to Cocoa's Foundation and Application Kit (AppKit) classes. A complement to Apple's documentation, Cocoa in a Nutshell is the only reference to the classes, functions, types, constants, protocols, and methods that make up Cocoa's Foundation and Application Kit frameworks, based on the Jaguar release (Mac OS X 10.2).

Peer-reviewed and approved by Apple's engineers to be part of the Apple Developer Connection (ADC) Series, Cocoa in a Nutshell is the book developers will want close at hand as they work. It's the desktop quick reference they can keep by their side to look something up quickly without leaving their work.

Cocoa in a Nutshell is the book developers will want close at hand as they work. It's the desktop quick reference they can keep by their side to look something up quickly without leaving their work.

Table of Contents

  1. Cocoa in a Nutshell
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. Preface
      1. What Is Cocoa?
        1. The Cocoa Development Environment
        2. Cocoa Design Patterns
        3. Benefits
        4. Languages
      2. How This Book Is Organized
      3. Conventions Used in This Book
      4. How the Quick Reference Was Generated
      5. Comments and Questions
      6. Acknowledgments
        1. From Mike
        2. From Duncan
    3. I. Introducing Cocoa
      1. 1. Objective-C
        1. Objects
          1. Dynamic Typing
          2. Static Typing
        2. Messaging
          1. Structure of a Message
            1. Nested messages
            2. Messaging nil
          2. How Messages Are Resolved into Methods
          3. Selectors
        3. Classes
          1. The Root Class
          2. Defining a Class
            1. The interface
            2. Scoping instance variables
            3. The implementation
          3. Special Variables
          4. Class Methods
          5. Overriding Superclass Methods
        4. Creating Object Instances
          1. Designated initializers
        5. Memory Management
          1. Retaining Objects in Accessor Methods
        6. Deallocating Objects
        7. Categories
          1. Protocols
        8. Naming Conventions
      2. 2. Foundation
        1. Data
          1. Immutable Versus Mutable Classes
          2. Basic Types
            1. Strings
            2. Comparing strings
            3. Attributed strings
            4. Working with strings: character sets and scanners
            5. NSCharacterSet
            6. NSScanner
            7. Numbers
          3. Collections
            1. Arrays
            2. Sets
            3. Dictionaries
            4. Enumerators
            5. Memory management in collections
          4. Dates and Time
          5. Binary Data
        2. Key-Value Coding
        3. Working with Files
          1. The File Manager
          2. File Handles
        4. Bundles and Resource Management
          1. Loading Resources
          2. Loading Code
        5. Archiving Objects
          1. Keyed Archiving
        6. User Defaults
        7. Notifications
        8. Operating System Interaction
          1. Process Info
          2. Tasks
        9. Threaded Programming
          1. Locks
            1. NSLock
            2. NSRecursiveLock
            3. NSConditionLock
      3. 3. The Application Kit
        1. AppKit Design Patterns
          1. Model-View-Controller
          2. Target/Action
        2. Nibs
          1. Outlets and Actions
        3. Application Architecture
          1. The Application
            1. NSApplicationMain
            2. The application delegate
            3. The run loop
          2. The Window
            1. Delegate methods
          3. The View
            1. Managing the view hierarchy
        4. Controls
          1. Cells
        5. Menus
        6. Sheets
        7. Drawers
        8. Toolbars
        9. Event Handling
          1. Event Objects
          2. The Responder Chain
        10. Document-Based Applications
      4. 4. Drawing and Imaging
        1. The Role of Quartz
        2. Coordinate Systems
        3. Graphics Contexts
        4. Working with Paths
          1. Drawing to Views
          2. Line Attributes
            1. Path flatness
            2. Line dashes and phase
            3. Line cap style
            4. Line join styles
            5. Miter limit
            6. Winding rule
        5. Drawing Text
          1. Attributed strings
        6. Working with Color
        7. Working with Images
          1. NSImage
            1. Compositing
            2. Drawing into an image
          2. NSImageRep
          3. NSBitmapImageRep
        8. Transformations
      5. 5. Text Handling
        1. Text System Architecture
          1. NSTextView
          2. NSTextStorage
          3. NSLayoutManager
          4. NSTextContainer
          5. How Text Is Laid Out
        2. Assembling the Text System
          1. Layout Scenarios
            1. Simple layout
            2. Paginating text
            3. Multicolumn text
            4. Multiple simultaneous layouts
          2. NSLayoutManager Delegation
      6. 6. Networking
        1. Hosts
        2. URL Resources
          1. Working with URLs
          2. URL Handles
            1. Managing subclasses
        3. Rendezvous Network Services
          1. NSNetService
            1. Initializing NSNetService for publication
            2. NSNetService delegate methods
            3. Errors
          2. NSNetServiceBrowser
            1. Searching for domains
        4. Sockets
        5. NSFileHandle
      7. 7. Interapplication Communication
        1. NSPipe
          1. Distributed Notifications
            1. Suspending delivery
          2. Distributed Objects
            1. DO architecture
            2. Setting up a server
            3. Connecting to a remote object
            4. DO and threads
            5. Making DO more efficient and reliable
            6. Handling communication failures
      8. 8. Other Frameworks
        1. AddressBook
          1. Working with Multiple-Value Objects
          2. Defining New Properties
          3. Searching
          4. Notifications
          5. Odds and Ends
            1. Creating a vCard from a record
            2. Adding an image to a record
        2. The Message Framework
        3. Disc Recording Frameworks
          1. The DiscRecording Framework
            1. DRBurn
            2. DRErase
            3. DRTrack
            4. Preparing audio content
            5. Preparing data content
          2. The DiscRecordingUI Framework
            1. How to record
        4. Third-Party Frameworks
    4. II. API Quick Reference
      1. 9. Foundation Types and Constants
        1. Data Types
          1. NSCalculationError
          2. NSComparisonResult
          3. NSDecimal
          4. NSHashEnumerator
          5. NSHashTable
          6. NSHashTableCallBacks
          7. NSInsertionPosition
          8. NSMapEnumerator
          9. NSMapTable
          10. NSMapTableKeyCallBacks
          11. NSMapTableValueCallBacks
          12. NSNetServicesError
          13. NSNotificationCoalescing
          14. NSNotificationSuspensionBehavior
          15. NSObjCValue
          16. NSPoint
          17. NSPointArray
          18. NSPointPointer
          19. NSPostingStyle
          20. NSPropertyListFormat
          21. NSPropertyListMutabilityOptions
          22. NSRange
          23. NSRangePointer
          24. NSRect
          25. NSRectArray
          26. NSRectEdge
          27. NSRectPointer
          28. NSRelativePosition
          29. NSRoundingMode
          30. NSSaveOptions
          31. NSSearchPathDirectory
          32. NSSearchPathDomainMask
          33. NSSize
          34. NSSizeArray
          35. NSSizePointer
          36. NSStringEncoding
          37. NSSwappedDouble
          38. NSSwappedFloat
          39. NSTestComparisonOperation
          40. NSTimeInterval
          41. NSUncaughtExceptionHandler
          42. NSURLHandleStatus
          43. NSWhoseSubelementIdentifier
          44. NSZone
        2. Enumerations
          1. NSNotFound
          2. NSOpenStepUnicodeReservedBase
          3. NSProcessInfo (Operating Systems)
          4. NSScriptCommand (General Command Execution Errors)
          5. NSScriptObjectSpecifier (Specifier Evaluation Errors)
          6. NSUndoCloseGroupingRunLoopOrdering
          7. Search Types
          8. String Encodings
        3. Global Variables
          1. File Attribute Keys
          2. Filesystem Attribute Keys
          3. File Type Attribute Keys
          4. Language-Dependent Date/Time Information
          5. Language-Dependent Numeric Information
          6. NSAppleEvent Timeouts
          7. NSConnectionReplyMode
          8. NSDefaultRunLoopMode
          9. NSJavaSetup Information
          10. NSHashTable Callbacks
          11. NSLocalNotificationCenterType
          12. NSMapTable Key Call Backs
          13. NSMapTable Value Callbacks
          14. NSNetServices Errors
          15. NSURL Schemes
          16. NSURLHandle FTP Property Keys
          17. NSURLHandle HTTP Property Keys
          18. NSUserDefaults Domains
          19. Zero Constants
        4. Constants
          1. NSDecimalMaxSize
          2. NSDecimalNoScale
          3. NSNotAnIntMapKey
          4. NSNotAPointerMapKey
        5. Exceptions
          1. Archiving
          2. Connection
          3. General Foundation Exception Names
          4. Keyed Archiving
          5. NSDecimalNumber
          6. NSFileHandle
          7. NSScriptKeyValueCoding
          8. NSString Handling
      2. 10. Foundation Functions
        1. Assertions
        2. Bundles
        3. Byte Ordering
        4. Decimals
        5. Java Setup
        6. Hash Tables
        7. HFS File Types
        8. Map Tables
        9. Object Allocation
        10. Objective-C Runtime
        11. Path Utilities
        12. Points
        13. Ranges
        14. Rects
        15. Sizes
        16. Uncaught Exceptions
        17. Zones
      3. 11. Application Kit Types and Constants
        1. Data Types
          1. NSAffineTransformStruct
          2. NSApplicationTerminateReply
          3. NSBackingStoreType
          4. NSBezelStyle
          5. NSBezierPathElement
          6. NSBitmapImageFileType
          7. NSBorderType
          8. NSBoxType
          9. NSButtonType
          10. NSCellAttribute
          11. NSCellImagePosition
          12. NSCellState
          13. NSCellType
          14. NSCharacterCollection
          15. NSCompositingOperation
          16. NSControlSize
          17. NSControlTint
          18. NSDocumentChangeType
          19. NSDragOperation
          20. NSDrawerState
          21. NSEventType
          22. NSFocusRingPlacement
          23. NSFontAction
          24. NSFontTraitMask
          25. NSGlyph
          26. NSGlyphInscription
          27. NSGlyphLayoutMode
          28. NSGlyphRelation
          29. NSGradientType
          30. NSImageAlignment
          31. NSImageCacheMode
          32. NSImageFrameStyle
          33. NSImageInterpolation
          34. NSImageLoadStatus
          35. NSImageRepLoadStatus
          36. NSImageScaling
          37. NSInterfaceStyle
          38. NSLayoutDirection
          39. NSLayoutStatus
          40. NSLineBreakMode
          41. NSLineCapStyle
          42. NSLineJoinStyle
          43. NSLineMovementDirection
          44. NSLineSweepDirection
          45. NSMatrixMode
          46. NSModalSession
          47. NSMultibyteGlyphPacking
          48. NSOpenGLContextAuxiliary
          49. NSOpenGLContextParameter
          50. NSOpenGLGlobalOption
          51. NSOpenGLPixelFormatAttribute
          52. NSOpenGLPixelFormatAuxiliary
          53. NSPopUpArrowPosition
          54. NSPrinterTableStatus
          55. NSPrintingOrientation
          56. NSPrintingPageOrder
          57. NSPrintingPaginationMode
          58. NSProgressIndicatorStyle
          59. NSProgressIndicatorThickness
          60. NSQTMovieLoopMode
          61. NSRequestUserAttentionType
          62. NSRulerOrientation
          63. NSSaveOperationType
          64. NSScreenAuxiliaryOpaque
          65. NSScrollArrowPosition
          66. NSScrollerArrow
          67. NSScrollerPart
          68. NSSelectionAffinity
          69. NSSelectionDirection
          70. NSSelectionGranularity
          71. NSTableViewDropOperation
          72. NSTabState
          73. NSTabViewItemAuxiliaryOpaque
          74. NSTabViewType
          75. NSTextAlignment
          76. NSTextFieldBezelStyle
          77. NSTextTabType
          78. NSTickMarkPosition
          79. NSTIFFCompression
          80. NSTitlePosition
          81. NSToolbarDisplayMode
          82. NSToolbarSizeMode
          83. NSToolTipTag
          84. NSTrackingRectTag
          85. NSTypesetterBehavior
          86. NSTypesetterGlyphInfo
          87. NSUsableScrollerParts
          88. NSWindingRule
          89. NSWindowAuxiliaryOpaque
          90. NSWindowButton
          91. NSWindowDepth
          92. NSWindowOrderingMode
          93. NSWritingDirection
        2. Enumerations
          1. NSApplication (Modal Session Return Values)
          2. NSAttributedString (Underlining)
          3. NSCell (Data Entry Types)
          4. NSCell (State Masks)
          5. NSColorPanel (Modes)
          6. NSColorPanel (Mode Masks)
          7. NSDragging (Operations)
          8. NSEvent (Action Flags)
          9. NSEvent (Function Key Unicodes)
          10. NSEvent (Modifier Flags)
          11. NSEvent (Types Defined by the Application Kit)
          12. NSEvent (Types Defined by the System)
          13. NSFont (Traits)
          14. NSGraphics (Alpha Values)
          15. NSGlyph (Reserved Glyph Codes)
          16. NSImageRep (Display Device Matching)
          17. NSOutlineView (Drop on Index)
          18. NSPanel (Alert Panel Return Values)
          19. NSPanel (Modal Panel Return Values)
          20. NSPanel (Style Mask)
          21. NSRunLoop (Ordering Modes for NSApplication)
          22. NSRunLoop (Ordering Modes for NSWindow)
          23. NSSavePanel (Tags for Subviews)
          24. NSText (Important Unicodes)
          25. NSText (Movement Codes)
          26. NSTextAttachment (Attachment Character)
          27. NSTextStorage (Editing)
          28. NSView (Resizing)
          29. NSWindow (Border Masks)
        3. Global Variables
          1. Color Space Names
          2. Display Device (Descriptions)
          3. NSAccessibility (Actions)
          4. NSAccessibility (Attributes)
          5. NSAccessibility (Exception Error Code Key)
          6. NSAccessibility (Notifications)
          7. NSAccessibility (Orientations)
          8. NSAccessibility (Roles)
          9. NSAccessibility (Subroles)
          10. NSApplication (Shared Application Object)
          11. NSAttributedString (Attributes)
          12. NSAttributedString (Character Shape Attribute)
          13. NSAttributedString (Document Type)
          14. NSAttributedString (Glyph Info Attribute)
          15. NSAttributedString (Underline Masks)
          16. NSBitmapImageRep (Attributes)
          17. NSColor (Grayscale Values)
          18. NSFont (Keys to the AFM Dictionary)
          19. NSFont (PostScript Transformation Matrix)
          20. NSGraphicsContext (Attributes)
          21. NSInterfaceStyleDefault
          22. NSPasteboard (Names)
          23. NSPasteboard (Types for Sound Data)
          24. NSPasteboard (Types for Standard Data)
          25. NSPrintInfo (Dictionary Keys)
          26. NSPrintPanel (Job Style Hints)
          27. NSRunLoop (Modes)
          28. NSToolbarItem (Standard Identifiers)
          29. NSWindow (Sizes)
          30. NSWindow (Window Levels)
          31. NSWorkspace (File Operation Constants)
          32. NSWorkspace (File Types)
        4. Exceptions
      4. 12. Application Kit Functions
        1. Accessibility
        2. Applications
        3. Events
        4. Fonts
        5. Graphics: General
        6. Graphics: Window Depth
        7. Interface Styles
        8. OpenGL
        9. Panels
        10. Pasteboards
        11. System Beep
      5. 13. Foundation Classes
        1. NSAppleEventDescriptor
        2. NSAppleEventManager
        3. NSAppleScript
        4. NSArchiver
        5. NSArray
        6. NSAssertionHandler
        7. NSAttributedString
        8. NSAutoreleasePool
        9. NSBundle
        10. NSCalendarDate
        11. NSCharacterSet
        12. NSClassDescription
        13. NSCloneCommand
        14. NSCloseCommand
        15. NSCoder
        16. NSConditionLock
        17. NSConnection
        18. NSCountCommand
        19. NSCountedSet
        20. NSCreateCommand
        21. NSData
        22. NSDate
        23. NSDateFormatter
        24. NSDecimalNumber
        25. NSDecimalNumberHandler
        26. NSDeleteCommand
        27. NSDeserializer
        28. NSDictionary
        29. NSDirectoryEnumerator
        30. NSDistantObject
        31. NSDistantObjectRequest
        32. NSDistributedLock
        33. NSDistributedNotificationCenter
        34. NSEnumerator
        35. NSException
        36. NSExistsCommand
        37. NSFileHandle
        38. NSFileManager
        39. NSFormatter
        40. NSGetCommand
        41. NSHost
        42. NSIndexSpecifier
        43. NSInvocation
        44. NSKeyedArchiver
        45. NSKeyedUnarchiver
        46. NSLock
        47. NSLogicalTest
        48. NSMachBootstrapServer
        49. NSMachPort
        50. NSMessagePort
        51. NSMessagePortNameServer
        52. NSMethodSignature
        53. NSMiddleSpecifier
        54. NSMoveCommand
        55. NSMutableArray
        56. NSMutableAttributedString
        57. NSMutableCharacterSet
        58. NSMutableData
        59. NSMutableDictionary
        60. NSMutableSet
        61. NSMutableString
        62. NSNameSpecifier
        63. NSNetService
        64. NSNetServiceBrowser
        65. NSNotification
        66. NSNotificationCenter
        67. NSNotificationQueue
        68. NSNull
        69. NSNumber
        70. NSNumberFormatter
        71. NSObject
        72. NSPipe
        73. NSPort
        74. NSPortCoder
        75. NSPortMessage
        76. NSPortNameServer
        77. NSPositionalSpecifier
        78. NSProcessInfo
        79. NSPropertyListSerialization
        80. NSPropertySpecifier
        81. NSProtocolChecker
        82. NSProxy
        83. NSQuitCommand
        84. NSRandomSpecifier
        85. NSRangeSpecifier
        86. NSRecursiveLock
        87. NSRelativeSpecifier
        88. NSRunLoop
        89. NSScanner
        90. NSScriptClassDescription
        91. NSScriptCoercionHandler
        92. NSScriptCommand
        93. NSScriptCommandDescription
        94. NSScriptExecutionContext
        95. NSScriptObjectSpecifier
        96. NSScriptSuiteRegistry
        97. NSScriptWhoseTest
        98. NSSerializer
        99. NSSet
        100. NSSetCommand
        101. NSSocketPort
        102. NSSocketPortNameServer
        103. NSSpecifierTest
        104. NSSpellServer
        105. NSString
        106. NSTask
        107. NSThread
        108. NSTimer
        109. NSTimeZone
        110. NSUnarchiver
        111. NSUndoManager
        112. NSUniqueIDSpecifier
        113. NSURL
        114. NSURLHandle
        115. NSUserDefaults
        116. NSValue
        117. NSWhoseSpecifier
      6. 14. Foundation Protocols
        1. NSCoding
        2. NSComparisonMethods
        3. NSCopying
        4. NSDecimalNumberBehaviors
        5. NSKeyValueCoding
        6. NSLocking
        7. NSMutableCopying
        8. NSObjCTypeSerializationCallBack
        9. NSObject
        10. NSScriptingComparisonMethods
        11. NSScriptKeyValueCoding
        12. NSScriptObjectSpecifiers
        13. NSURLHandleClient
      7. 15. Application Kit Classes
        1. NSActionCell
        2. NSAffineTransform
        3. NSApplication
        4. NSBezierPath
        5. NSBitmapImageRep
        6. NSBox
        7. NSBrowser
        8. NSBrowserCell
        9. NSButton
        10. NSButtonCell
        11. NSCachedImageRep
        12. NSCell
        13. NSClipView
        14. NSColor
        15. NSColorList
        16. NSColorPanel
        17. NSColorPicker
        18. NSColorWell
        19. NSComboBox
        20. NSComboBoxCell
        21. NSControl
        22. NSCursor
        23. NSCustomImageRep
        24. NSDocument
        25. NSDocumentController
        26. NSDrawer
        27. NSEPSImageRep
        28. NSEvent
        29. NSFileWrapper
        30. NSFont
        31. NSFontManager
        32. NSFontPanel
        33. NSForm
        34. NSFormCell
        35. NSGlyphInfo
        36. NSGraphicsContext
        37. NSHelpManager
        38. NSImage
        39. NSImageCell
        40. NSImageRep
        41. NSImageView
        42. NSInputManager
        43. NSInputServer
        44. NSLayoutManager
        45. NSMatrix
        46. NSMenu
        47. NSMenuItem
        48. NSMenuItemCell
        49. NSMenuView
        50. NSMovie
        51. NSMovieView
        52. NSMutableParagraphStyle
        53. NSNibConnector
        54. NSNibControlConnector
        55. NSNibOutletConnector
        56. NSOpenGLContext
        57. NSOpenGLPixelFormat
        58. NSOpenGLView
        59. NSOpenPanel
        60. NSOutlineView
        61. NSPageLayout
        62. NSPanel
        63. NSParagraphStyle
        64. NSPasteboard
        65. NSPDFImageRep
        66. NSPICTImageRep
        67. NSPopUpButton
        68. NSPopUpButtonCell
        69. NSPrinter
        70. NSPrintInfo
        71. NSPrintOperation
        72. NSPrintPanel
        73. NSProgressIndicator
        74. NSQuickDrawView
        75. NSResponder
        76. NSRulerMarker
        77. NSRulerView
        78. NSSavePanel
        79. NSScreen
        80. NSScroller
        81. NSScrollView
        82. NSSecureTextField
        83. NSSecureTextFieldCell
        84. NSSimpleHorizontalTypesetter
        85. NSSlider
        86. NSSliderCell
        87. NSSound
        88. NSSpellChecker
        89. NSSplitView
        90. NSStatusBar
        91. NSStatusItem
        92. NSStepper
        93. NSStepperCell
        94. NSTableColumn
        95. NSTableHeaderCell
        96. NSTableHeaderView
        97. NSTableView
        98. NSTabView
        99. NSTabViewItem
        100. NSText
        101. NSTextAttachment
        102. NSTextAttachmentCell
        103. NSTextContainer
        104. NSTextField
        105. NSTextFieldCell
        106. NSTextStorage
        107. NSTextTab
        108. NSTextView
        109. NSToolbar
        110. NSToolbarItem
        111. NSTypesetter
        112. NSView
        113. NSWindow
        114. NSWindowController
        115. NSWorkspace
      8. 16. Application Kit Protocols
        1. NSAccessibility
        2. NSChangeSpelling
        3. NSColorPickingCustom
        4. NSColorPickingDefault
        5. NSComboBoxCellDataSource
        6. NSComboBoxDataSource
        7. NSDraggingDestination
        8. NSDraggingInfo
        9. NSDraggingSource
        10. NSIgnoreMisspelledWords
        11. NSInputServerMouseTracker
        12. NSInputServiceProvider
        13. NSMenuItem
        14. NSMenuValidation
        15. NSNibAwaking
        16. NSOutlineViewDataSource
        17. NSServicesRequests
        18. NSTableDataSource
        19. NSTextAttachmentCell
        20. NSTextInput
        21. NSTextStorageScripting
        22. NSToolbarItemValidation
        23. NSToolTipOwner
        24. NSUserInterfaceValidations
        25. NSValidatedUserInterfaceItem
        26. NSWindowScripting
      9. Method Index
    5. III. Appendix
      1. A. Appendix: Resources for Cocoa Developers
        1. Apple Documentation
        2. Related Books
        3. Web Sites
        4. Mailing Lists
        5. Partnering with Apple
    6. Index
    7. About the Authors
    8. Colophon
    9. SPECIAL OFFER: Upgrade this ebook with O’Reilly