Effective Objective-C 2.0: 52 Specific Ways to Improve Your iOS and OS X Programs

Book description

Write Truly Great iOS and OS X Code with Objective-C 2.0!

Effective Objective-C 2.0 will help you harness all of Objective-C’s expressive power to write OS X or iOS code that works superbly well in production environments. Using the concise, scenario-driven style pioneered in Scott Meyers’ best-selling Effective C++, Matt Galloway brings together 52 Objective-C best practices, tips, shortcuts, and realistic code examples that are available nowhere else.

Through real-world examples, Galloway uncovers little-known Objective-C quirks, pitfalls, and intricacies that powerfully impact code behavior and performance. You’ll learn how to choose the most efficient and effective way to accomplish key tasks when multiple options exist, and how to write code that’s easier to understand, maintain, and improve. Galloway goes far beyond the core language, helping you integrate and leverage key Foundation framework classes and modern system libraries, such as Grand Central Dispatch.

Coverage includes

  • Optimizing interactions and relationships between Objective-C objects

  • Mastering interface and API design: writing classes that feel “right at home”

  • Using protocols and categories to write maintainable, bug-resistant code

  • Avoiding memory leaks that can still occur even with Automatic Reference Counting (ARC)

  • Writing modular, powerful code with Blocks and Grand Central Dispatch

  • Leveraging differences between Objective-C protocols and multiple inheritance in other languages

  • Improving code by more effectively using arrays, dictionaries, and sets

  • Uncovering surprising power in the Cocoa and Cocoa Touch frameworks

  • Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Dedication Page
    5. Contents
    6. Preface
      1. About This Book
      2. Audience for This Book
      3. What This Book Covers
    7. Acknowledgments
    8. About the Author
    9. 1. Accustoming Yourself to Objective-C
      1. Item 1: Familiarize Yourself with Objective-C’s Roots
      2. Item 2: Minimize Importing Headers in Headers
      3. Item 3: Prefer Literal Syntax over the Equivalent Methods
      4. Item 4: Prefer Typed Constants to Preprocessor #define
      5. Item 5: Use Enumerations for States, Options, and Status Codes
    10. 2. Objects, Messaging, and the Runtime
      1. Item 6: Understand Properties
      2. Item 7: Access Instance Variables Primarily Directly When Accessing Them Internally
      3. Item 8: Understand Object Equality
      4. Item 9: Use the Class Cluster Pattern to Hide Implementation Detail
      5. Item 10: Use Associated Objects to Attach Custom Data to Existing Classes
      6. Item 11: Understand the Role of objc_msgSend
      7. Item 12: Understand Message Forwarding
      8. Item 13: Consider Method Swizzling to Debug Opaque Methods
      9. Item 14: Understand What a Class Object Is
    11. 3. Interface and API Design
      1. Item 15: Use Prefix Names to Avoid Namespace Clashes
      2. Item 16: Have a Designated Initializer
      3. Item 17: Implement the description Method
      4. Item 18: Prefer Immutable Objects
      5. Item 19: Use Clear and Consistent Naming
      6. Item 20: Prefix Private Method Names
      7. Item 21: Understand the Objective-C Error Model
      8. Item 22: Understand the NSCopying Protocol
    12. 4. Protocols and Categories
      1. Item 23: Use Delegate and Data Source Protocols for Interobject Communication
      2. Item 24: Use Categories to Break Class Implementations into Manageable Segments
      3. Item 25: Always Prefix Category Names on Third-Party Classes
      4. Item 26: Avoid Properties in Categories
      5. Item 27: Use the Class-Continuation Category to Hide Implementation Detail
      6. Item 28: Use a Protocol to Provide Anonymous Objects
    13. 5. Memory Management
      1. Item 29: Understand Reference Counting
      2. Item 30: Use ARC to Make Reference Counting Easier
      3. Item 31: Release References and Clean Up Observation State Only in dealloc
      4. Item 32: Beware of Memory Management with Exception-Safe Code
      5. Item 33: Use Weak References to Avoid Retain Cycles
      6. Item 34: Use Autorelease Pool Blocks to Reduce High-Memory Waterline
      7. Item 35: Use Zombies to Help Debug Memory-Management Problems
      8. Item 36: Avoid Using retainCount
    14. 6. Blocks and Grand Central Dispatch
      1. Item 37: Understand Blocks
      2. Item 38: Create typedefs for Common Block Types
      3. Item 39: Use Handler Blocks to Reduce Code Separation
      4. Item 40: Avoid Retain Cycles Introduced by Blocks Referencing the Object Owning Them
      5. Item 41: Prefer Dispatch Queues to Locks for Synchronization
      6. Item 42: Prefer GCD to performSelector and Friends
      7. Item 43: Know When to Use GCD and When to Use Operation Queues
      8. Item 44: Use Dispatch Groups to Take Advantage of Platform Scaling
      9. Item 45: Use dispatch_once for Thread-Safe Single-Time Code Execution
      10. Item 46: Avoid dispatch_get_current_queue
    15. 7. The System Frameworks
      1. Item 47: Familiarize Yourself with the System Frameworks
      2. Item 48: Prefer Block Enumeration to for Loops
      3. Item 49: Use Toll-Free Bridging for Collections with Custom Memory-Management Semantics
      4. Item 50: Use NSCache Instead of NSDictionary for Caches
      5. Item 51: Keep initialize and load Implementations Lean
      6. Item 52: Remember that NSTimer Retains Its Target
    16. Index

    Product information

    • Title: Effective Objective-C 2.0: 52 Specific Ways to Improve Your iOS and OS X Programs
    • Author(s):
    • Release date: May 2013
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780133386950