Introduction 1 Who Should Read This Book 1What This Book Covers 1Downloading the Sample Files 2How This Book Is Organized 2 PART I: GETTING STARTED WITH OBJECTIVE-C HOUR 1: Overview of the Developer Program 7 Introducing Objective-C 7Enrolling as an Apple Developer 8Choosing Your Program 8 Selecting Your Membership Category 9 Registering for Your Apple ID 10Setting Up the Development Environment 11 Talking Xcode 11 Introducing the Xcode Workspace 12 Getting Up and Running with Your First Project 16Summary 17Q&A 18Workshop 18 Quiz 18 Quiz Answers 18 Activities 19 HOUR 2: Object-Oriented Programming with Objective-C 21 Object-Oriented Programming in the Objective-C World 21 Implementing Object-Oriented Programming 21 Building Object-Oriented Projects 22 Looking at the Frameworks 23Creating C with Objects 24 Start Thinking in Objective-C 24 Understanding Data Abstraction 24 Considering Classes and Instances 25 Exploring Encapsulation 25 Using Accessors to Manage Encapsulation 28Managing Inheritance in the Objective-C World 29Summary 30Q&A 31Workshop 31 Quiz 31 Quiz Answers 31 Activities 31 HOUR 3: Using Object-Oriented Features in Objective-C 33 Communicating to Methods with Messages 33 Looking at a Simple Message 33 Declaring a Method 34 Using Class Methods 35 Working with id--Strongly and Weakly Typed Variables 35 Nesting Messages 36 Looking at Method Signatures and Parameters 36Allocating and Initializing Objects 37Summary 39Q&A 39Workshop 39 Quiz 39 Quiz Answers 39 Activities 39 HOUR 4: Using Xcode 5 41 Getting to Work with Xcode 41Keeping Track of Your Source Code 46 Exploring Source Code Control 47 Working in a Source Code Repository World 48 Using Git with Xcode 50Using a Remote Repository 58Summary 61Q&A 61Workshop 61 Quiz 61 Quiz Answers 61 Activities 62 HOUR 5: Using Compiler Directives 63 Exploring Your Projects 63 Looking at the iOS Project 64 Looking at the OS X Project 64 Looking at Both Projects 65Working with Compiler Directives 66 Working with Basic Directives 66 Looking at Prefix Headers 67 Looking at Plain C Code in main.m 69 Investigating Header (.h) Files 70 Looking Inside Message (.m) Files 71Using Objective-C Compiler Directives 74Summary 74Q&A 74Workshop 75 Quiz 75 Quiz Answers 75 Activities 75 PART II: WORKING WITH THE OBJECTIVE-C BASICS HOUR 6: Exploring Messaging and a Testbed App 77 Setting Up the Testbed Apps 77Adding a Text Field and Connecting It to Your Code 81 Adding the Text Field 82 Connecting the Text Field to the Code 88Sending a Message to the Text Field 92Reviewing the Message Syntax 94Summary 95Q&A 95Workshop 96 Quiz 96 Quiz Answers 96 Activities 96 HOUR 7: Declaring a Class in an Interface File 97 Letting Xcode Do the Work 97 Designing Classes 97 Getting Ready to Create the Class 98Exploring Class Hierarchies 104 Calling Superclass Methods 104 Introducing Protocols 106Declaring Classes 106 Writing a Basic Class Declaration 106 Using Forward References 107Summary 109Q&A 109Workshop 109 Quiz 109 Quiz Answers 109 Activities 109 HOUR 8: Declaring Instance Variables in an Interface File 111 Declaring Instance Variables and Properties 111Using the Class 111 Placing a Class Instance in Context 112 Choosing the Context 113Creating an Instance Variable for CurrencyConverter with id 114What Happens When Execution Stops 115 Dynamic Binding 117Creating an Instance Variable for CurrencyConverter with the Class Name 117Creating an Instance Variable for CurrencyConverter with a Superclass Name 119Managing Instance Variable Visibility 123Summary 124Q&A 124Workshop 124 Quiz 124 Quiz Answers 124 Activities 125 HOUR 9: Declaring Properties in an Interface File 127 Comparing Interface Variables and Properties 127 Reviewing Basic Variable Declarations 128 Creating Declared Properties: The Basics 130 Dealing with Memory for Objects 132 Working with Attributes for Declared Properties 133Using Declared Properties 133 Accessing the Property with Message Syntax 134 Accessing the Property with Dot Syntax 134Using Attributes 135 Accessor Methods 136 Writability 136 Setter Semantics 137 Atomicity 137 Using Other Attribute Decorators 137Implementing Properties 138 Creating Accessors with @synthesize 138 Promising Data with @dynamic 139Summary 139Q&A 139Workshop 139 Quiz 139 Quiz Answers 139 Activities 140 HOUR 10: Declaring Methods in an Interface File 141 Working with Methods in a Class 141Reviewing Method Syntax 142 Distinguishing Between Class and Instance Methods 142 Exploring the Method Declaration 143 Writing the Method Declaration 146 Returning Complex Data Structures from Methods 146Summary 147Q&A 147Workshop 148 Quiz 148 Quiz Answers 148 Activities 148 HOUR 11: Declaring Actions in an Interface File 149 Introducing Actions 149 What Actions Can Do for You 150Comparing Actions in OS X and iOS 159 Disconnecting Actions 161Summary 162Q&A 162Workshop 163 Quiz 163 Quiz Answers 163 Activities 163 HOUR 12: Routing Messages with Selectors 165 Getting Inside Objective-C Messages 165 Receiver and Selector Objects in Messages 166Getting Inside the Objective-C Runtime 167Working with SEL and @selector () 168Using performSelector 169 Creating a Selector with @selector () 169 Creating a Selector from a String 169 Using a Selector 170Using NSInvocation 172 Creating an NSInvocation 172 Using NSInvocation Properties 173 Invoking an NSInvocation 175Testing Whether an Instance Can Respond to a Selector 175Summary 176Q&A 176Workshop 177 Quiz 177 Quiz Answers 177 Activities 177 HOUR 13: Building on the Foundation 179 Exploring the Foundation Framework 179Foundation Classes 180 Root Classes 180 Other Classes 181Foundation Paradigms and Policies 182 Mutability 182 Class Clusters 183 Notifications 184Summary 187Q&A 187Workshop 187 Quiz 187 Quiz Answers 187 Activities 187 HOUR 14: Defining a Class in an Implementation File 189 Working with a New Project 189 Reconsidering Dynamic Typing 190 Designing the (Currency) Converter 190Creating a New App 193Implementing a Method 197Expanding the Class with init Methods 200Summary 202Q&A 202Workshop 202 Quiz 202 Quiz Answers 202 Activities 203 HOUR 15: Organizing Data with Collections 205 Collecting Objects 205Getting Familiar with Property Lists 207 Using Collections in Property Lists 208 Building Collections from Property Lists at Runtime 209Comparing the Collection Classes 209Creating a Collection 210 Using the Common Collection Creation Methods 211Using Objective-C Literal Syntax 212 Reading and Writing Arrays 213 Reading and Writing Dictionaries 213 Creating Sets 214Enumerating a Collection 214 Examining NSEnumerator Methods 214 Creating NSEnumerator Instances for Collections 215Testing Membership in a Collection 217Accessing an Object in a Collection 218Summary 218Q&A 218Workshop 219 Quiz 219 Quiz Answers 219 Activities 219 HOUR 16: Managing Memory and Runtime Objects 221 Managing Objects in Memory 221Managing Reference Counts Manually 222 Looking at Memory Management Before ARC 223 Summarizing Memory Management 225Managing Reference Counts with ARC 225 Using Declared Property Attributes 226Variable Qualifiers 227Autoreleasing Variables 228Summary 229Q&A 229Workshop 229 Quiz 229 Quiz Answers 229 Activities 229 PART III: EXPANDING AND EXTENDING CLASSES HOUR 17: Extending a Class with Protocols and Delegates 231 Exploring the Pros and Cons of Subclassing 231Introducing the Example 232Working with Protocols 232Working with Delegates 233Putting Protocols and Delegates Together 233Looking Deeper Inside Protocols 236Summary 236Q&A 236Workshop 237 Quiz 237 Quiz Answers 237 Activities 237 HOUR 18: Extending a Class with Categories and Extensions 239 Comparing Categories and Protocols 239 Choosing When to Use a Category 240 Comparing Other Techniques with Categories 240Comparing Categories with Subclasses 241 Modifying a Class Hierarchy 241 Confining Modifications to Categories 242Working with Categories 242Using Class Extensions 245Working with Informal Protocols 246Summary 246Q&A 246Workshop 247 Quiz 247 Quiz Answers 247 Activities 247 HOUR 19: Using Associative References and Fast Enumeration 249 Catching Up on Objective-C 2.0 Time-Saving Features 249Extending Classes by Adding Instance Variables (Sort of) 250 Adding an Associative Reference 251 Getting and Setting an Associative Reference 252 Removing an Associative Reference for a Key 254 Removing All Associative References from an Object. 254Using Fast Enumeration 254 Using Fast Enumeration 254 Using Fast Enumeration with an NSEnumerator 256Summary 256Q&A 256Workshop 257 Quiz 257 Quiz Answers 257 Activities 257 HOUR 20: Working with Blocks 259 Revisiting Blocks 259Looking at Callbacks 260 Considering Callback Routines 263Introducing Blocks 264 Creating a Block as a Block Variable 264 Using a Block Variable 265Exploring Blocks in Cocoa 266 NSString enumerateLinesUsingBlock 267 NSArray enumerateObjectsUsingBlock 268 NSSet enumerateObjectsUsingBlock 268Looking Deeper into Cocoa Blocks and Memory 269Summary 269Q&A 269Workshop 270 Quiz 270 Quiz Answers 270 Activities 270 PART IV: BEYOND THE BASICS HOUR 21: Handling Exceptions and Errors 271 Rethinking Exceptions and Errors 271Introducing the Exception and Error Classes 272 Using Exceptions 273 Using Errors 273 Looking Inside NSException 274 Looking Inside NSError 274Identifying an Exception 277Throwing an Exception 278Catching an Exception 280Summary 280Q&A 280Workshop 280 Quiz 280 Quiz Answers 281 Activities 281 HOUR 22: Grand Central Dispatch: Using Queues and Threading 283 Getting Started with Concurrency 283 Looking at Processors Inside Computers 283 Using Concurrency Without Rewriting User Apps 284 Using Threads for Concurrency 284 Introducing Grand Central Dispatch (GCD) 285Introducing Queues 286 Dispatch Queues 287Dispatch Sources 287 Operation Queues 287Using Dispatch Queues 288 Using Global Concurrent Dispatch Queues 288 Adding a T.
Sams Teach Yourself Objective-C in 24 Hours