- ホーム
- > 洋書
- > 英文書
- > Computer / Languages
Full 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 includesOptimizing interactions and relationships between Objective-C objectsMastering interface and API design: writing classes that feel "right at home"Using protocols and categories to write maintainable, bug-resistant codeAvoiding memory leaks that can still occur even with Automatic Reference Counting (ARC)Writing modular, powerful code with Blocks and Grand Central DispatchLeveraging differences between Objective-C protocols and multiple inheritance in other languagesImproving code by more effectively using arrays, dictionaries, and setsUncovering surprising power in the Cocoa and Cocoa Touch frameworks
Contents
Preface xi Acknowledgments xvAbout the Author xviiChapter 1: Accustoming Yourself to Objective-C 1Item 1: Familiarize Yourself with Objective-C's Roots 1Item 2: Minimize Importing Headers in Headers 4Item 3: Prefer Literal Syntax over the Equivalent Methods 8Item 4: Prefer Typed Constants to Preprocessor #define 12Item 5: Use Enumerations for States, Options, and Status Codes 17Chapter 2: Objects, Messaging, and the Runtime 25Item 6: Understand Properties 25Item 7: Access Instance Variables Primarily Directly When Accessing Them Internally 33Item 8: Understand Object Equality 36Item 9: Use the Class Cluster Pattern to Hide Implementation Detail 42Item 10: Use Associated Objects to Attach Custom Data to Existing Classes 47Item 11: Understand the Role of objc_msgSend 50Item 12: Understand Message Forwarding 54Item 13: Consider Method Swizzling to Debug Opaque Methods 62Item 14: Understand What a Class Object Is 66Chapter 3: Interface and API Design 73Item 15: Use Prefix Names to Avoid Namespace Clashes 73Item 16: Have a Designated Initializer 78Item 17: Implement the description Method 84Item 18: Prefer Immutable Objects 89Item 19: Use Clear and Consistent Naming 95Item 20: Prefix Private Method Names 102Item 21: Understand the Objective-C Error Model 104Item 22: Understand the NSCopying Protocol 109Chapter 4: Protocols and Categories 115Item 23: Use Delegate and Data Source Protocols for Interobject Communication 115Item 24: Use Categories to Break Class Implementations into Manageable Segments 123Item 25: Always Prefix Category Names on Third-Party Classes 127Item 26: Avoid Properties in Categories 130Item 27: Use the Class-Continuation Category to Hide Implementation Detail 133Item 28: Use a Protocol to Provide Anonymous Objects 140Chapter 5: Memory Management 145Item 29: Understand Reference Counting 145Item 30: Use ARC to Make Reference Counting Easier 153Item 31: Release References and Clean Up Observation State Only in dealloc 162Item 32: Beware of Memory Management with Exception-Safe Code 165Item 33: Use Weak References to Avoid Retain Cycles 168Item 34: Use Autorelease Pool Blocks to Reduce High-Memory Waterline 173Item 35: Use Zombies to Help Debug Memory-Management Problems 177Item 36: Avoid Using retainCount 183Chapter 6: Blocks and Grand Central Dispatch 187Item 37: Understand Blocks 188Item 38: Create typedefs for Common Block Types 194Item 39: Use Handler Blocks to Reduce Code Separation 197Item 40: Avoid Retain Cycles Introduced by Blocks Referencing the Object Owning Them 203Item 41: Prefer Dispatch Queues to Locks for Synchronization 208Item 42: Prefer GCD to performSelector and Friends 213Item 43: Know When to Use GCD and When to Use Operation Queues 217Item 44: Use Dispatch Groups to Take Advantage of Platform Scaling 220Item 45: Use dispatch_once for Thread-Safe Single-Time Code Execution 225Item 46: Avoid dispatch_get_current_queue 226Chapter 7: The System Frameworks 233Item 47: Familiarize Yourself with the System Frameworks 233Item 48: Prefer Block Enumeration to for Loops 236Item 49: Use Toll-Free Bridging for Collections with Custom Memory-Management Semantics 243Item 50: Use NSCache Instead of NSDictionary for Caches 248Item 51: Keep initialize and load Implementations Lean 252Item 52: Remember that NSTimer Retains Its Target 258Index 265