Advanced Mac OS X Programming: The Big Nerd Ranch Guide

Book description

While there are several books on programming for Mac OS X, Advanced Mac OS X Programming: The Big Nerd Ranch Guide is the only one that contains explanations of how to leverage the powerful underlying technologies. This book gets down to the real nitty-gritty. The third edition is updated for Mac OS X 10.5 and 10.6 and covers new technologies like DTrace, Instruments, Grand Central Dispatch, blocks, and NSOperation.

Table of contents

  1. Title Page
  2. Dedication
  3. Acknowledgments
  4. Foreword
  5. Introduction
    1. Mac OS X: Built to Evolve
    2. This Book
    3. Typographical Conventions
    4. Online Materials
  6. 1. C and Objective-C
    1. C
      1. The Compiler pipeline
      2. The C preprocessor
        1. Preprocessor symbols
        2. Stringization and concatenation
        3. Conditional compilation
        4. Predefined symbols
        5. File inclusion
        6. Macro hygiene
        7. Multiline macros
      3. Const and volatile variables
      4. Variable argument lists
        1. Varargs gotchas
        2. QuietLog
        3. Variadic macros
      5. Bitwise operations
        1. Bitwise operators
        2. Setting and clearing bits
    2. Objective-C
      1. C callbacks in Objective-C
      2. Objective-C 2.0
        1. Protocols
        2. Class extensions
        3. Fast enumeration
        4. Runtime enhancements and garbage collection
        5. Properties
    3. Exercises
  7. 2. The Compiler
    1. Handy Flags
      1. Debugging
      2. Warnings
    2. Seeing Preprocessor Output
    3. Seeing the Generated Assembly Code
    4. Compiler Optimization
    5. GCC Extensions
    6. Name Mangling
      1. Testing the compiler version
      2. The Optimizer
      3. Vectorization
    7. Even More Compiler Flags
    8. 64-Bit Computing
      1. The 64-bit programming model
        1. 64-bit cleanliness
        2. Should you go 64-bit?
      2. New Objective-C runtime
    9. Universally Fat Binaries
      1. Fat binaries from the command line
      2. Fat binaries in Xcode
      3. Fat binary considerations
  8. 3. Blocks
    1. Block Syntax
    2. Return Values
    3. Accessing Enclosing Scope
    4. Changing Enclosing Scope
    5. Block Variables
    6. Variable Capture Redux
    7. Blocks as Objects
    8. When To Copy
    9. Blocks in Collections
    10. Block Retain Cycles
    11. New API Using Blocks
    12. For the More Curious: Blocks Internals
      1. Implementation
        1. Block literals
        2. __block variables
      2. Debugging
        1. gcc’s debugging information
        2. clang’s debugging information
      3. Dumping runtime information
      4. Evolving the implementation
      5. Compiler-generated names
    13. Exercises
  9. 4. Command-Line Programs
    1. The Basic Program
    2. Inside the Central Loop
    3. Changing Behavior By Name
    4. Looking at the Environment
    5. Parsing the Command Line
    6. getopt_long()
    7. User Defaults
  10. 5. Exceptions, Error Handling, and Signals
    1. errno
    2. setjmp, longjmp
    3. Signals
      1. Handling a signal
      2. Blocking signals
        1. Handling signals with sigaction()
      3. Signal issues
        1. Reentrancy
        2. Race conditions
    4. Exception Handling in Cocoa
      1. Classic exception handling
      2. Native exception handling
      3. Subclassing NSApplication to catch exceptions
      4. 64-bit Objective-C runtime
    5. NSError
    6. Logging
      1. syslog()
      2. ASL
        1. ASL messages
        2. ASL queries
    7. For the More Curious: Assertions
      1. Static assertions
      2. AssertMacros.h
    8. Exercises
  11. 6. Libraries
    1. Static Libraries
    2. Shared Libraries
      1. But I included the header!
    3. Frameworks
    4. Libraries or Frameworks?
    5. Writing Plug-ins
      1. Bundles in Cocoa
    6. Shared Libraries and dlopen
      1. dlopen()
      2. dlsym()
      3. BundlePrinter
    7. For the More Curious: libtool
    8. For the More Curious: otool
    9. For the More Curious: Runtime Environment Variables
    10. Exercises
  12. 7. Memory
    1. Virtual Memory
    2. Program Memory Model
    3. Memory Lifetime
    4. Dynamic Memory Allocation
      1. malloc()
      2. free()
      3. realloc()
      4. calloc()
      5. alloca()
    5. Memory Ownership Issues
      1. Nodepools
    6. Debugging Memory Problems
      1. Common API issues
      2. Memory corruption
        1. MallocGuardEdges
        2. MallocStackLogging and MallocStackLoggingNoCompact
        3. MallocScribble
        4. Guard Malloc
      3. Memory leaks
        1. Memory leaks in Cocoa
    7. Other Tools
      1. ps
      2. Resource limits
      3. Miscellaneous tools
      4. vm_stat
    8. Objective-C Garbage Collection
      1. How to use it
      2. How it works
      3. Strong and weak references
      4. Finalize methods
      5. Non Objective-C objects
      6. External reference counts
      7. The "new" collection classes
      8. GC and threads
      9. Debugging
    9. Exercises
  13. 8. Debugging With GDB
    1. What Is a Debugger?
    2. Using GDB from the Command Line
      1. A sample GDB session
    3. GDB Specifics
    4. Help
    5. Stack Traces
    6. Program Listings
    7. Breakpoints
    8. Displaying Data
    9. Changing Data
    10. Changing Execution Flow
    11. Handy Tricks
    12. Debugging Techniques
      1. Tracking down problems
      2. Debugger techniques
    13. For the More Curious: Core Files
    14. For the More Curious: Stripping
    15. More Advanced GDB Commands
      1. Threads
  14. 9. DTrace
    1. Overview
      1. The D language
      2. Scripts
    2. Probes
    3. Providers
      1. BEGIN and END providers
      2. pid provider
      3. syscall provider
      4. profile provider
      5. proc provider
      6. fbt provider
    4. Actions
      1. Variables
      2. Scoped variables
      3. Built-in variables
    5. Functions
    6. Arrays
      1. C arrays
    7. Predicates
    8. Aggregates
      1. Aggregate-related functions
    9. Random Leftovers
      1. The C preprocessor
      2. Pragmas
      3. Objective-C
    10. Exercises
  15. 10. Performance Tuning
    1. The End of Free Performance
    2. Approaches To Performance
    3. Major Causes of Performance Problems
      1. Memory
        1. Locality of Reference
        2. Caches
        3. Memory is the New I/O
      2. CPU
      3. Disk
      4. Graphics
      5. Before using any of the profiling tools
    4. Command-Line Tools
      1. time
      2. dtruss
      3. fs_usage and sc_usage
      4. top
      5. Stochastic profiling
      6. sample
    5. Precise Timing with mach_absolute_time()
    6. GUI Tools
      1. Activity Monitor
      2. Instruments
        1. Window layout
          1. The Toolbar
        2. Looking at memory leaks
        3. More Memory: Heapshots
        4. Time Profiler
        5. Other Instruments
          1. Memory
          2. Automation
          3. Power
          4. Graphics
          5. File System
          6. System Details
          7. Symbol Trace and DTrace
    7. Summary
    8. Exercises
  16. 11. Files, Part 1: I/O and Permissions
    1. Unbuffered I/O
      1. Opening a file
      2. Writing to a file
      3. Reading from a file
      4. Closing files
      5. Changing the read/write offset
      6. Atomic operations
      7. Scatter / Gather I/O
      8. creat()
      9. Blocking I/O
    2. Buffered I/O
      1. Opening files
      2. Closing files
      3. Text I/O
      4. Binary I/O
      5. Positioning
    3. Formatted I/O
    4. Misc Functions
    5. Buffered I/O vs. Unbuffered I/O
    6. Removing Files
    7. Temporary Files
    8. File Permissions
      1. Users and groups
      2. File permissions
    9. Directory Permissions
    10. Permission-Check Algorithms
    11. For the More Curious: Memory-Mapped Files
  17. 12. Files, Part 2: Directories, File Systems, and Links
    1. Directories
      1. Creation and destruction
      2. Directory iteration
        1. The opendir() Family
      3. Current working directory
    2. Inside The File System
    3. Links
      1. Hard links
      2. Symbolic links
      3. Mac OS aliases
      4. API for links
    4. File Metadata
      1. stat()
      2. getattrlist()
        1. Describing the attributes
        2. Parsing the buffer
      3. Metadata in batches
    5. Mac OS X Specific Weirdness
      1. Resource forks
      2. .DS_Store
      3. Disk I/O and sleep
    6. For The More Curious
      1. Differences between HFS+ and UFS
      2. Other random calls
      3. Other random programs
      4. Access control lists
      5. Extended attributes
  18. 13. NSFileManager - Cocoa and the File System
    1. Making and Manipulating Paths
      1. NSString path utilities
      2. NSURL path utilities
    2. Finding Standard Directories
      1. Path utilities
      2. URL utilities
    3. File Metadata
      1. Metadata through paths
      2. Metadata through URLs
    4. File Operations
      1. Path operations
      2. URL operations
      3. Symbolic links
    5. Directory Enumeration
      1. Enumeration with paths
      2. Enumeration with URLs
    6. File References and Bookmarks
      1. File references
      2. Bookmarks
    7. Make a File Browser
      1. Create the DirEntry class
      2. Edit the nib file adding NSTreeController
      3. Using NSBrowser and DirEntry
      4. Adding deletion
    8. NSWorkspace
    9. Exercises
  19. 14. Network Programming With Sockets
    1. Addresses
    2. Sockets Address Data Structures
      1. IPv4 address structures
      2. IPv6 address structures
    3. Network Byte Order
    4. Address Conversions
      1. IPv4- and IPv6-compatible functions
      2. IPv4-specific functions
    5. Domain Name Lookup
    6. Simple Network Programming
      1. Server coding
      2. Constructing an address
      3. bind
      4. listen
      5. accept
    7. Client Coding
      1. connect
    8. More Advanced Issues
      1. Multiplexing connections
      2. Message boundaries
    9. For the More Curious: Datagrams
    10. Exercises
  20. 15. CFRunLoop
    1. CFSocket
    2. CFHost
    3. GUI Chatter Client
    4. Runloop Chatter Server
    5. The System Configuration Framework
      1. Architecture
      2. Basic API
      3. Seeing all values
      4. Creating SCFMonitor
    6. For the More Curious: Run Loop Observers
    7. Exercises
  21. 16. kqueue and FSEvents
    1. kqueue()
    2. Events
    3. Registering and Handling Events
    4. kqueues for Signal Handling
    5. kqueues for Socket Monitoring
    6. kqueues for File System Monitoring
    7. kqueues and Runloops
    8. fsevents
    9. fseventsd
    10. Watching Directories
    11. Events
    12. History
    13. Visibility
    14. FSEvents API
      1. Creating the stream
      2. Hook up to the runloop
        1. The FSEvents callback
        2. Miscellaneous calls
    15. Example
    16. Exercises
  22. 17. Bonjour
    1. Publishing an NSNetService
      1. Make chatterserver Zeroconf-compliant
    2. Browsing Net Services
      1. Make ChatterClient browse for servers
    3. For the More Curious: TXT Records
    4. Exercises
  23. 18. Multiprocessing
    1. Process Scheduling
    2. Convenience Functions
    3. fork
    4. Parent and Child Lifetimes
    5. exec
    6. Pipes
    7. fork() Gotchas
    8. Summary
    9. Exercises
  24. 19. Using NSTask
    1. NSProcessInfo
    2. NSTask
    3. NSFileHandle
    4. NSPipe
    5. Creating an App that Creates a New Process
    6. Non-blocking reads
      1. Create the header and edit the xib file
      2. Edit the code
    7. Exercises
  25. 20. Multithreading
    1. Posix Threads
      1. Creating threads
      2. Synchronization
      3. Mutexes
      4. Deadlocks
      5. Condition variables
    2. Cocoa and Threading
      1. NSThread
      2. Cocoa and thread safety
      3. Objective-C @synchronized blocks
    3. For the More Curious: Thread Local Storage
    4. For the More Curious: Read/Write Locks
    5. Exercises
  26. 21. Operations
    1. Simple-Lifetime Operations
      1. NSOperationQueue
      2. Threading issues
    2. MandelOpper
      1. Bitmap
      2. BitmapView
      3. CalcOperation
      4. MandelOpperAppDelegate
      5. NSBlockOperation
    3. Complex-Lifetime Operations
      1. KVO properties
    4. ImageSnarfer
      1. ImageCanvas
      2. SnarfOperation
      3. NSURLConnection delegate methods
      4. ImageSnarferAppDelegate
      5. Mop-up
    5. Exercises
  27. 22. Grand Central Dispatch
    1. GCD Terminology
    2. Queues
    3. Object-Oriented Design
    4. Dispatch API
      1. Queues
      2. Dispatching
      3. Memory management
    5. WordCounter
    6. Iteration
    7. Safe Global Initialization
    8. Time, Time, Time
    9. Dispatch Groups
    10. Dispatch Sources
      1. Signal sources
      2. File read source
      3. File write source
      4. Timer sources
      5. Custom sources
      6. Under the Hood
    11. Semaphores
    12. GCD or NSOperation?
    13. For the More Curious: Synchronizing Tasks
    14. For the More Curious: The dispatch_debug() Function
    15. Exercises
  28. 23. Accessing the Keychain
    1. Items and Attribute Lists
    2. Searching for Items
    3. Reading Data From an Item
    4. Editing the Keychain
    5. Getting Specific Keychains
    6. Keychain Access
    7. Making a New Keychain Item
    8. Convenience Functions
    9. Code Signing
    10. Exercises
  29. Index
  30. More From Big Nerd Ranch...

Product information

  • Title: Advanced Mac OS X Programming: The Big Nerd Ranch Guide
  • Author(s):
  • Release date: August 2011
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780321706256