Learning Objective-C 2.0: A Hands-On Guide to Objective-C for Mac and iOS Developers

Paperback
from $0.00

Author: Robert Clair

ISBN-10: 0321711386

ISBN-13: 9780321711380

Category: Personal Computers

Search in google:

Get Started Fast with Objective-C 2.0 Programming for OS X, iPhone, iPod touch, and iPadIf you want to learn Objective-C 2.0 to write programs for Mac OS X, iPhone, iPad, or iPod touch, you’ve come to the right place! Concise, readable, and friendly, Learning Objective-C 2.0 is the perfect beginner’s guide to the latest version of Objective-C.Longtime Mac OS X and iPhone developer Robert Clair covers everything from the absolute basics to Objective-C 2.0’s newest innovations. Clair begins with a practical refresher on C and object-oriented programming and walks you through creating your first Objective-C program with Xcode. Next, you’ll master each core language feature, from objects and classes to messaging, frameworks, and protocols. Every concept is illustrated with simple examples, and many chapters contain hands-on practice exercises.Throughout, Learning Objective-C 2.0 focuses on the features, concepts, and techniques that matter most day to day. The result is an outstanding first book for everyone who wants to begin programming for iPhone, iPod touch, iPad, or Mac OS X.COVERAGE INCLUDESUnderstanding methods, messages, and the Objective-C messaging systemDefining classes, creating object instances, and using class objectsUsing categories to extend classes without subclassingSimplifying development with Objective-C 2.0 declared propertiesUsing protocols to emphasize behavior rather than classWorking with common Foundation classes for strings, arrays, dictionaries, sets, and number objectsUsing Objective-C control structures, including Objective-C 2.0’s new fast enumeration constructUnderstanding application security and hiding the declaration of methods that should stay privateUsing the new blocks feature provided in Objective-C 2.0

Preface xxiiiAcknowledgments xxxiAbout the Author xxxiiiPart I: Introduction to Objective-C 1Chapter 1: C, The Foundation of Objective-C 3The Structure of a C Program 4Variables 8Operators 16Expressions and Statements 21Program Flow 22Preprocessor 31printf 33Using gcc and gdb 35Summary 37Exercises 37Chapter 2: More About C Variables 41Memory Layout of an Objective-C Program 41Automatic Variables 42External Variables 43Declaration Keywords 44Scope 47Dynamic Allocation 49Summary 51Exercises 52Chapter 3: An Introduction to Object-Oriented Programming 55Object-Oriented Programming 55An Introduction to Objective-C 58Objective-C Additions 66Summary 71Chapter 4: Your First Objective-C Program 73Building with Xcode 73Objective-C Program Structure 76An Object-Oriented Hello World 79HelloObjectiveC.m 86Summary 88Exercises 88Part II: Language Basics 91Chapter 5: Messaging 93Methods 93Messaging 96Messaging Details 98Under the Hood 106Message Forwarding 108Efficiency 109Introspection and Other Runtime Fun 111Summary 112Exercises 113Chapter 6: Classes and Objects 115Defining a Class 115Subclassing a Class 119Creating Objects 126Destroying Objects 135Copying Objects 136Summary 141Exercises 141Chapter 7: The Class Object 143Class Objects 143Other Class Methods 147Mimicking Class Variables 151Summary 157Exercises 157Chapter 8: Frameworks 159What Is a Framework? 159Cocoa Frameworks 161AppKit 162Core Foundation 163Core Graphics 166Core Animation 167Other Apple-Supplied Frameworks 167Third-Party Frameworks 168Under the Hood 168Summary 170Chapter 9: Common Foundation Classes 171Immutable and Mutable Classes 171Class Clusters 172NSString 173Collection Classes 177NSNumber 183NSNull 184NSData 185NSURL 186Structures 187Summary 188Exercises 189Chapter 10: Control Structures in Objective-C 191if Statements 191for Statements and Implicit Loops 195while Statements and NSEnumerator 196Fast Enumeration 199An Example Using Fast Enumeration 201Exceptions 205Summary 210Exercises 211Chapter 11: Categories, Extensions, and Security 213Categories 213Extensions 218Instance Variable Scope (Access Control) 220Access Control for Methods 221Namespaces 221Security 222Calling C Functions from Objective-C 224Summary 226Exercises 226Chapter 12: Properties 229Accessing Instance Variables Outside of an Object (Don’t Do It) 230Declaring and Implementing Accessors 231Accessors Using Properties 233The @property Statement 236More About @dynamic 238Properties and Memory Management 240Subclassing and Properties 240Hidden Setters for readonly Properties 242Properties as Documentation 242Dot Syntax 243Summary 246Exercises 247Chapter 13: Protocols 249Protocols 249Using Protocols 250TablePrinter Example 253Protocol Objects and Testing for Conformance 260Informal Protocols 261Summary 262Exercises 263Part III: Advanced Concepts 265Chapter 14: Reference Counting 267The Problem 268Reference Counting 269Receiving Objects 271Ownership 273dealloc 274Returning Objects 276retainCount 281Multithreading 282When Retain Counts Go Bad 283Retain Cycles 285The Final Goodbye: When Programs Terminate 288Summary 288Exercises 289Chapter 15: Garbage Collection 291Garbage Collection: The Theory 291Garbage Collection: The Practice 293Using Garbage Collection 294Finalizers 296malloc and Garbage Collection 297Core Foundation Objects and Garbage Collection 298Some Bumps in the Road 299Garbage Collection Pro and Con 303Summary 305Exercises 305Chapter 16: Blocks 309Function Pointers 310The Trouble with Function Pointers 314NSInvocation 315Blocks 317Some Philosophical Reservations 331Summary 332Exercises 332Part IV: Appendices 335Appendix A: Reserved Words and Compiler Directives 337Appendix B: Toll-Free Bridged Classes 339Appendix C: 32- and 64-Bit 341Kernel and User Programs in 64-Bit 342Coding Differences for 64-Bit Programs 342Performance 342Compiling for 64-Bit 343More Information 343Appendix D: Runtimes, Old and New 345Synthesized Instance Variables 345The Fragile Base Class Problem—Solved 347Appendix E: Resources for Objective-C 349Apple Resources 349Internet Resources 350Groups 350Books 350Index 351