Register your product to gain access to bonus material or receive a coupon.
In Full Color
Code samples are syntax highlighted as in Xcode!!
In just 24 sessions of one hour or less, learn how to build powerful mobile applications with Apple’s Cocoa Touch technology for the iPhone and iPod touch! Using this book’s straightforward, step-by-step approach, you’ll master every skill and technology you need, from handling user interaction and building effective user interfaces to accessing the Internet, playing media, and using the iPhone and iPod touch’s incredible sensing capabilities. Each lesson builds on what you’ve already learned, giving you a rock-solid foundation for real-world success!
Step-by-step instructions carefully walk you through the most common Cocoa Touch programming tasks.
Quizzes and Exercises at the end of each chapter help you test your knowledge.
By the Way notes present interesting information related to the discussion.
Did You Know? tips offer advice or show you easier ways to perform tasks.
Watch Out! cautions alert you to possible problems and give you advice on how to avoid them.
Introduction 1
About This Book 1
About You 2
About Objective-C 2
What You Need 2
How to Read This Book 3
Conventions Used in This Book 3
PART I: Understanding the Objective-C Language
HOUR 1: Starting Your First Application: A Calculator 5
Setting Up Your Development Tools 5
Using Xcode 6
Using Interface Builder 13
Summary 20
Workshop 21
Exercise 21
HOUR 2: Handling Interaction 23
Objective-C 23
Binding an Object to the User Interface 31
Basic Memory Management 39
Invoking Methods on nil 41
Type Checking Rules 41
Type Equivalence 42
Type Checking 42
Summary 44
Q&A 45
Workshop 45
Exercise 46
HOUR 3: Simplifying Your Code 47
Managing Memory with NSAutoReleasePools 47
Objective-C Strings 52
Introducing the Debugger 62
Understanding Messaging 65
Debugging a Real Bug 68
Using Shorthands 70
Summary 74
Q&A 74
Workshop 74
Exercises 75
HOUR 4: Making the Calculator Calculate 77
A Simple Calculator 78
Mutable Classes: Making a “Printing” Calculator 82
Dynamic Objective-C 88
Summary 96
Q&A 96
Workshop 96
Exercises 97
HOUR 5: Adding Variables to the Calculator 99
A Better Model/Controller Split 99
Using an NSDictionary to Add Variables to the Calculator 106
The Key-Value Coding and Observing Protocols 113
Summary 120
Workshop 120
Exercise 121
PART II: User-Interface Foundations
HOUR 6: Understanding How the User Interface Is Built 123
User-Interface Building-Blocks: Views 123
Building the UI from Views 136
Summary 147
Q&A 147
Workshop 148
Exercise 148
HOUR 7: Understanding How Events Are Processed 149
Run Loops and Core Foundation 149
How Cocoa Uses the Run Loop 155
Touch Event Dispatching 160
Summary 167
Q&A 168
Workshop 168
Exercises 169
HOUR 8: Drawing User-Interface Elements 171
Adding Images to UIButton 171
Core Graphics 178
Drawing Your Own Button 194
Summary 199
Q&A 199
Workshop 199
Exercises 200
HOUR 9: Layers and Core Animation: Creating a Cover Flow Clone 201
Placing Layers in 3D Space 202
Using Core Animation 208
Creating a Cover Flow Clone 220
Summary 230
Q&A 230
Workshop 231
Exercises 231
PART III: Advanced User-Interface Elements
HOUR 10: Using View Controllers 233
View Controllers 233
Adding a Scientific Mode to the Calculator 242
Summary 250
Q&A 250
Workshop 251
Exercises 252
HOUR 11: Displaying Tables 253
Creating Tables 254
Using Table Cells 261
Creating a Twitter Application 268
Summary 272
Q&A 273
Workshop 273
Exercises 274
HOUR 12: Adding Navigation and Tab Bar Controllers 275
Using Modal View Controllers 275
Saving Application Defaults 279
Using Tab Bars 283
Using Navigation Bars 287
Summary 295
Q&A 295
Workshop 295
Exercises 296
HOUR 13: Adding Undo and Redo Functionality 297
Creating Your Own Undo/Redo Manager 297
Using NSUndoManager 305
Summary 307
Q&A 307
Workshop 308
Exercise 308
PART IV: Accessing the Internet
HOUR 14: Accessing the Network 309
How Networks Work 309
How the Web Works 316
Using Cocoa Touch to Access the Web 321
Making the Twitter Application Deal with Errors 328
Summary 330
Q&A 331
Workshop 331
Exercises 332
HOUR 15: Showing a Web Page 335
Understanding UIWebView 335
Using UIWebViews 339
Using WebKit Extensions 345
Summary 352
Q&A 352
Workshop 353
Exercises 354
PART V: Saving and Retrieving Data
HOUR 16: Adding Application Preferences 355
Retrieving Settings Set by the Settings Application 356
Creating a Settings Bundle for the Settings Application 357
Dynamically Updating Data from the Network 365
Summary 368
Q&A 369
Workshop 369
Exercises 370
HOUR 17: Using the SQLite Database 371
Saving and Reading Data from Files 371
Saving and Reading Data from an SQLite Database 373
Summary 385
Q&A 385
Workshop 385
Exercise 386
HOUR 18: Using Core Data 387
Using NSSortDescriptor and NSPredicate 387
Using Core Data 390
Using Xcode to Design Objects 404
Summary 407
Q&A 407
Workshop 407
Exercises 408
PART VI: Interacting with the World
HOUR 19: Playing and Recording Media 409
Playing and Recording Audio 409
Playing Video Files 426
Summary 429
Q&A 430
Workshop 430
Exercises 431
HOUR 20: Sensing the World 433
Using the iPhone’s Accelerometer 433
Determining the iPhone’s Location 438
Taking Photos and Making Short Videos 444
Summary 446
Q&A 446
Workshop 446
Exercises 447
HOUR 21: Sharing Data 449
Using Custom URLs 449
Using Pasteboards 452
Exporting Data 455
Summary 459
Q&A 459
Workshop 460
Exercises 461
PART VII: Completing Your Application
HOUR 22: Debugging 463
Using gdb, dtrace, valgrind, and nib2objc 463
Resolving Cocoa Misunderstandings 472
Summary 477
Q&A 477
Workshop 477
Exercise 478
HOUR 23: Optimizing Performance 79
Profiling Your Code . 479
Optimizing Your Memory Usage 486
Optimizing Your Code’s Speed 495
Summary 500
Q&A 500
Workshop 501
Exercise 502
HOUR 24: Shipping Your Application 503
Polishing Your Application for Submission 503
Localizing Your Application 506
Submitting Your Application to the App Store 514
Summary 517
Q&A 518
Workshop 519
Exercise 520
APPENDIX A: C Primer (Online) 521
Functions 521
Primitive Types 521
Basic Operators 522
Function Signatures 522
Interface Files 522
System Libraries 522
Composite Structures 523
Memory Access 523
Arrays 524
Dynamic Memory Allocation 524
Strings 524
Types 525
New Kinds of Errors 525
APPENDIX B: Troubleshooting Xcode (Online) 527
Logging in to the Developer Website 527
Obtaining Permission to Upload Your Application to Your Device 529
Building Your Application to Run on a Device 531
Updating Mobile Provisions 533
Debugging the Ambiguous Matches Error 534
Uploading Your Application to Your Device 534
Checking Changes That Do Not Show Up 540
Checking the App Store Executable 541
APPENDIX C: Resources 543
This Book’s Website 543
Books and Papers 543
Web Resources 545
APPENDIX D: Advanced Topics (Online) 547
Testing String Mutability with Exceptions 547
Uncaught Exceptions 547
The Implementation of Exceptions. 548
NSZones 549
Creating Singletons by Overriding allocWithZone: 550
Extending Objects by Overriding allocWithZone: 551
How Applications Start 552
Threads 553
pthreads 554
NSThreads 555
Deciding Whether to Use Threading or One-Shot Invocation 560
Types of Layers 562
View Controller Hierarchy Used in the Twitter Application 566
Index 567