Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
This is the Rough Cut version of the printed book.
Get Started Fast with Objective-C 2.0 Programming for OS X Mountain Lion, iOS 5.1, and Beyond
Fully updated for Xcode 4.4, Learning Objective-C 2.0, Second Edition, is today’s most useful beginner’s guide to Objective-C 2.0. One step at a time, it will help you master the newest version of Objective-C 2.0 and start writing high-quality programs for OS X 10.8 Mountain Lion, iOS 5.1, and all of Apple’s newest computers and devices.
Top OS X and iOS developer Robert Clair first reviews the essential object and C concepts that every Objective-C 2.0 developer needs to know. Next, he introduces the basics of the Objective-C 2.0 language itself, walking through code examples one line at a time and explaining what’s happening behind the scenes.
This revised edition thoroughly introduces Apple’s new Automated Reference Counting (ARC), while also teaching conventional memory-management techniques that remain indispensable. Carefully building on what you’ve already learned, Clair progresses to increasingly sophisticated techniques in areas ranging from frameworks to security. Every topic has been carefully chosen for its value in real-world, day-to-day programming, and many topics are supported by hands-on practice exercises.
Coverage includes
· Reviewing key C techniques and concepts, from program structure and formats to variables and scope
· Understanding how objects and classes are applied in Objective-C 2.0
· Writing your first Objective-C program with Xcode 4.4
· Using messaging to efficiently perform tasks with objects
· Getting started with Apple’s powerful frameworks and foundation classes
· Using Objective-C control structures, including Fast Enumeration and exception handling
· Adding methods to classes without subclassing
· Using declared properties to save time and simplify your code
· Mastering ARC and conventional memory management, and knowing when to use each
· Using Blocks to prepare for concurrency with Apple’s Grand Central Dispatch
· Leveraging Xcode 4.4 improvements to enums and @implementation
Preface xxv
Acknowledgments xxxv
About the Author xxxvii
Part I: Introduction to Objective-C 1
Chapter 1: C, the Foundation of Objective-C 3
The Structure of a C Program 4
Variables 8
Operators 16
Expressions and Statements 21
Program Flow 23
Preprocessor 33
Command Line Compiling and Debugging 37
Summary 39
Exercises 39
Chapter 2: More about C Variables 43
Memory Layout of a C Program 43
Automatic Variables 44
External Variables 46
Declaration Keywords 46
Scope 50
Dynamic Allocation 51
Summary 54
Exercises 55
Chapter 3: An Introduction to Object-Oriented Programming 57
Object-Oriented Programming 57
An Introduction to Objective-C 60
Objective-C Additions 68
Summary 74
Chapter 4: Your First Objective-C Program 75
Building with Xcode 75
Objective-C Program Structure 79
An Object-Oriented “Hello World” 83
main.m 90
Summary 92
Exercises 92
Part II: Language Basics 95
Chapter 5: Messaging 97
Methods 97
A Simple Method 97
Methods with Arguments 98
Messaging 100
Messaging Details 103
Under the Hood 111
Message Forwarding 113
Efficiency 114
Introspection and Other Runtime Fun 115
Summary 117
Exercises 117
Chapter 6: Classes and Objects 119
Defining a Class 119
Subclassing a Class 123
Creating Objects 131
Destroying Objects 139
Copying Objects 141
Summary 146
Exercises 146
Chapter 7: The Class Object 149
Class Objects 149
Other Class Methods 153
Mimicking Class Variables 158
Summary 163
Exercises 164
Chapter 8: Frameworks 167
What Is a Framework? 168
Cocoa and Cocoa Touch 169
AppKit 170
UIKit 171
Core Foundation 172