| help | account  


Programming in Objective-C 2.0
View Larger Image
Stephen G. Kochan
Addison-Wesley, Paperback, 2nd edition, Estimated Publication Date January 2009, 600 pages, ISBN 0321566157
List Price: $44.99
Our Price: $28.95
You Save: $16.04 (36% Off)


FREE Shipping on Orders over $40!*
Availability: Not-Yet-Published. Estimated publication date is January 2009. If you order it today we can ship it to you when it arrives.

Books on similar topics, in best-seller order:Books from the same publisher, in best-seller order:

A complete introduction to the Objective-C language for Mac OS X and iPhone development

Objective-C has become the standard programming language for application development on the Mac OS X and iPhone platforms. A powerful yet simple object-oriented programming language that’s based on the C programming language, Objective-C is widely available not only on OS X but across many operating systems that support the gcc compiler, including Linux, Unix, and Windows systems.

Programming in Objective-C 2.0 provides the new programmer a complete, step-by-step introduction to the Objective-C language. The book does not assume previous experience with either C or object-oriented programming languages, and it includes many detailed, practical examples of how to put Objective-C to use in your everyday programming needs.

The second edition of this book has been updated and expanded to cover Objective-C 2.0. It shows not only how to take advantage of the Foundation framework’s rich built-in library of classes but also how to use the iPhone SDK to develop programs designed specifically for the iPhone and iPod Touch.

“The best book on any programming language that I’ve ever read. If you want to learn Objective-C, buy it.” –Calvin Wolcott

“An excellent resource for a new programmer who wants to learn Objective-C as their first programming language–a woefully underserved market.” –Pat Hughes

 

Table of Contents

1 Introduction 1

What You Will Learn from This Book 2

How This Book Is Organized 3

Acknowledgments 5

I: The Objective-C 2.0 Language

2 Programming in Objective-C 9

Compiling and Running Programs 9

Using Xcode 10

Using Terminal 16

Explanation of Your First Program 18

Displaying the Values of Variables 22

Summary 25

Exercises 25

3 Classes, Objects, and Methods 27

What Is an Object, Anyway? 27

Instances and Methods 28

An Objective-C Class for Working with Fractions 30

The @interface Section 33

Choosing Names 33

Instance Variables 35

Class and Instance Methods 35

The @implementation Section 37

The program Section 38

Accessing Instance Variables and Data Encapsulation 44

Summary 47

Exercises 47

4 Data Types and Expressions 49

Data Types and Constants 49

Type int 49

Type float 51

Type double 51

Type char 51

Qualifiers: long, long long, 53

Type id 55

Arithmetic Expressions 56

Operator Precedence 56

Integer Arithmetic and the Unary Minus Operator 58

The Modulus Operator 60

Integer and Floating-Point Conversions 62

The Type Cast Operator 63

Assignment Operators 64

A Calculator Class 65

Bit Operators 67

The Bitwise AND Operator 68

The Bitwise Inclusive-OR Operator 69

The Bitwise Exclusive-OR Operator 69

The Ones Complement Operator 70

The Left Shift Operator 71

The Right Shift Operator 72

Types: _Bool, _Complex, and 73

Exercises 73

5 Program Looping 77

The for Statement 78

Keyboard Input 84

Nested for Loops 86

for Loop Variants 88

The while Statement 89

The do Statement 94

The break Statement 95

The continue Statement 96

Summary 96

Exercises 96

6 Making Decisions 99

The if Statement 99

The if-else Construct 104

Compound Relational Tests 106

Nested if Statements 109

The else if Construct 111

The switch Statement 120

Boolean Variables 123

The Conditional Operator 128

Exercises 129

7 More on Classes 133

Separate Interface and Implementation Files 133

Synthesized Accessor Methods 139

Accessing Properties Using the Dot Operator 140

Multiple Arguments to Methods 141

Methods Without Argument Names 143

Operations on Fractions 144

Local Variables 146

Method Arguments 147

The static Keyword 147

The self Keyword 149

Allocating and Returning Objects from Methods 150

Extending Class Definitions and the Interface File 155

Exercises 156

8 Inheritance 157

It All Begins at the Root 157

Finding the Right Method 161

Extension Through Inheritance: Adding New Methods 162

A Point Class and Memory Allocation 166

The @class Directive 167

Classes Owning Their Objects 171

Overriding Methods 175

Which Method Is Selected? 177

Overriding the dealloc Method and the Keyword super 179

Extension Through Inheritance: Adding New Instance Variables 181

Abstract Classes 183

Exercises 184

9 Polymorphism, Dynamic Typing, and Dynamic Binding 187

Polymorphism: Same Name, Different Class 187

Dynamic Binding and the id Type 191

Compile Time Versus Runtime Checking 193

The id Data Type and Static Typing 194

Argument and Return Types with Dynamic Typing 195

Asking Questions About Classes 195

Exception Handling Using @try 200

Exercises 203

10 More on Variables and Data Types 205

Initializing Classes 205

Scope Revisited 207

Directives for Controlling Instance Variable Scope 208

External Variables 209

Static Variables 211

Storage Class Specifiers 213

auto 213

const 214

volatile 214

Enumerated Data Types 215

The typedef Statement 218

Data Type Conversions 220

Conversion Rules 220

Sign Extension 221

Exercises 222

11 Categories and Protocols 225

Categories 225

Some Notes About Categories 230

Protocols 231

Informal Protocols 234

Composite Objects 235

Exercises 236

12 The Preprocessor 239

The #define Statement 239

More Advanced Types of Definitions 241

The # Operator 246

The ## Operator 247

The #import Statement 248

Conditional Compilation 250

The #ifdef, #endif, #else 250

The #if and #elif Preprocessor Statements 252

The #undef Statement 253

Exercises 253

13 Underlying C Language Features 255

Arrays 256

Initializing Array Elements 258

Character Arrays 259

Multidimensional Arrays 260

Functions 262

Arguments and Local Variables 263

Returning Function Results 265

Functions, Methods, and Arrays 268

Structures 271

Initializing Structures 277

Arrays of Structures 278

Structures Within Structures 278

Additional Details About Structures 280

Don’t Forget About Object-Oriented Programming! 282

Pointers 283

Pointers and Structures 287

Pointers, Methods, and Functions 288

Pointers and Arrays 290

Operations on Pointers 300

Pointers and Memory Addresses 301

Unions 302

They’re Not Objects! 305

Miscellaneous Language Features 305

Compound Literals 305

The goto Statement 306

The null Statement 306

The Comma Operator 306

The sizeof Operator 307

Command-Line Arguments 308

How Things Work 310

Fact #1: Instance Variables are Stored in Structures 310

Fact #2: An Object Variable is Really a Pointer 311

Fact #3: Methods are Functions, and Message Expressions are Function Calls 311

Fact #4: The id Type is a Generic Pointer Type 311

Exercises 312

II: The Foundation Framework

14 Introduction to the Foundation Framework 317

Foundation Documentation 317

15 Numbers, Strings, and Collections 321

Number Objects 322

A Quick Look at the Autorelease Pool 323

String Objects 326

More on the NSLog Function 327

Mutable Versus Immutable Objects 328

Mutable Strings 333

Where Are All Those Objects Going? 338

Array Objects 341

Making an Address Book 345

Synthesized AddressCard Methods 349

Fast Enumeration 354

Sorting Arrays 362

Dictionary Objects 367

Enumerating a Dictionary 368

Set Objects 370

Exercises 375

16 Working with Files 377

Managing Files and Directories: NSFileManager 378

Working with the NSData Class 383

Working with Directories 384

Enumerating the Contents of a Directory 387

Working with Paths: NSPathUtilities.h 389

Common Methods for Working with Paths 392

Copying Files and Using the NSProcessInfo Class 393

Basic File Operations: NSFileHandle 397

Exercises 402

17 Memory Management 405

The Autorelease Pool 405

Reference Counting 406

Reference Counting and Strings 409

Reference Counting and Instance Variables 411

An Autorelease Example 418

Summary of Memory-Management Rules 419

Garbage Collection 420

Exercises 422

18 Copying Objects 423

The copy and mutablecopy Methods 424

Shallow Versus Deep Copying 426

Implementing the <NSCopying> Protocol 429

Copying Objects in Setter and Getter Methods 432

Exercises 434

19 Archiving 435

Archiving with XML Property Lists 435

Archiving with NSKeyedArchiver 437

Writing Encoding and Decoding Methods 440

Using NSData to Create Custom Archives 447

Using the Archiver to Copy Objects 450

Exercises 452

III: Cocoa and the iPhone SDK

20 Introduction to Cocoa 455

Framework Layers 455

Cocoa Touch 456

21 Writing iPhone Applications 459

The iPhone SDK 459

Your First iPhone Application 459

Creating a New iPhone Application Project 461

Entering Your Code 463

Designing the Interface 467

An iPhone Fraction Calculator 476

Starting the New Fraction_Calculator Project 478

Defining the View Controller 480

The Fraction Class 485

A Calculator Class That Deals with Fractions 488

Designing the UI 490

Summary 491

Exercises 492

IV: Appendixes

A Glossary 497

B Objective-C 2.0 Language Summary 505

C Address Book Source Code 569

D Resources 575

 

About the Author

Stephen G. Kochan is author or coauthor of several bestselling books on the C language, including Programming in C, Programming in ANSI C, and Topics in C Programming. He has written extensively on Unix and is author of Exploring the Unix System and Unix Shell Programming. Kochan has been programming Macintosh computers since the introduction of the first Mac in 1984 and wrote Programming C for the Mac for the Apple Press Library as well as Beginning AppleScript (Wrox).




Forgot your password?
FAQs
Shipping Options
Returns
Your Orders
Your Account