文件名称:Cocoa Fundamentals Guide
文件大小:4.39MB
文件格式:PDF
更新时间:2016-05-09 03:29:06
IOS Mac Objective-C Xcode
Introduction Introduction 11 Organization of This Document 11 See Also 12 Chapter 1 What Is Cocoa? 13 The Cocoa Environment 13 Introducing Cocoa 13 How Cocoa Fits into Mac OS X 14 How Cocoa Fits into iOS 16 Features of a Cocoa Application 18 The Development Environment 21 Platform SDKs 21 Overview of Development Workflows 21 Xcode 22 Interface Builder 24 The iOS Simulator Application 26 Performance Applications and Tools 27 The Cocoa Frameworks 29 Foundation 30 AppKit (Mac OS X) 38 UIKit (iOS) 44 Comparing AppKit and UIKit Classes 49 Core Data 50 Other Frameworks with a Cocoa API 52 A Bit of History 53 Chapter 2 Cocoa Objects 55 A Simple Cocoa Command-Line Tool 55 Object-Oriented Programming with Objective-C 56 The Objective-C Advantage 56 The Dynamism of Objective-C 57 Extensions to the Objective-C Language 58 Using Objective-C 64 The Root Class 66 NSObject 67 Root Class—and Protocol 67 Overview of Root-Class Methods 68 Interface Conventions 69 Instance and Class Methods 70 2010-12-13 | © 2010 Apple Inc. All Rights Reserved. 3 CONTENTS Object Retention and Disposal 70 How the Garbage Collector Works 71 How Memory Management Works 73 Object Creation 77 Allocating an Object 77 Initializing an Object 78 The dealloc and finalize Methods 85 Class Factory Methods 86 Introspection 87 Evaluating Inheritance Relationships 87 Method Implementation and Protocol Conformance 88 Object Comparison 89 Object Mutability 90 Why Mutable and Immutable Object Variants? 90 Programming with Mutable Objects 91 Class Clusters 95 Without Class Clusters: Simple Concept but Complex Interface 95 With Class Clusters: Simple Concept and Simple Interface 96 Creating Instances 96 Class Clusters with Multiple Public Superclasses 96 Creating Subclasses Within a Class Cluster 97 Toll-Free Bridging 102 Creating a Singleton Instance 104 Chapter 3 Adding Behavior to a Cocoa Program Starting Up 107 What Happens in the main Function 107 Using a Cocoa Framework 109 Kinds of Framework Classes 109 Cocoa API Conventions 110 Inheriting from a Cocoa Class 112 When to Override a Method 113 When to Make a Subclass 115 Basic Subclass Design 117 The Form of a Subclass Definition 117 Overriding Superclass Methods 119 Instance Variables 119 Entry and Exit Points 121 Initialize or Decode? 122 Storing and Accessing Properties 123 Key-Value Mechanisms 128 Object Infrastructure 129 Error Handling 130 Resource Management and Other Efficiencies Functions, Constants, and Other C Types 132 107 4 2010-12-13 | © 2010 Apple Inc. All Rights Reserved. 131 CONTENTS When the Class Is Public (Mac OS X) 132 Multithreaded Cocoa Programs 133 Multithreading and Multiprocessing Resources 133 Multithreading Guidelines for Cocoa Programs 135 Are the Cocoa Frameworks Thread Safe? 136 Chapter 4 Cocoa Design Patterns 137 What Is a Design Pattern? 137 A Solution to a Problem in a Context 137 An Example: The Command Pattern 138 How Cocoa Adapts Design Patterns 139 Abstract Factory 139 Adapter 140 Chain of Responsibility 141 Command 142 Composite 143 Decorator 145 Facade 147 Iterator 148 Mediator 148 Memento 151 Observer 153 Proxy 154 Receptionist 155 Singleton 158 Template Method 158 The Model-View-Controller Design Pattern 160 Roles and Relationships of MVC Objects 160 Types of Cocoa Controller Objects 162 MVC as a Compound Design Pattern 163 Design Guidelines for MVC Applications 165 Model-View-Controller in Cocoa (Mac OS X) 167 Object Modeling 167 Entities 168 Attributes 168 Relationships 169 Accessing Properties 170 Chapter 5 Communicating with Objects 175 Communication in Object-Oriented Programs 175 Outlets 175 Delegates and Data Sources 176 How Delegation Works 177 The Form of Delegation Messages 178 2010-12-13 | © 2010 Apple Inc. All Rights Reserved. 5 CONTENTS Delegation and the Cocoa Application Frameworks 179 Data Sources 180 Implementing a Delegate for a Custom Class 181 The Target-Action Mechanism 182 The Target 182 The Action 183 Target-Action in the AppKit Framework 183 Target-Action in UIKit 186 Bindings (Mac OS X) 187 How Bindings Work 187 How You Establish Bindings 188 Notifications 190 When and How to Use Notifications 191 The Notification Object 193 Notification Centers 193 Notification Queues 194 Ownership of Delegates, Observers, and Targets 196 Document Revision History 199