Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Preface

Preface

Welcome to the world of iPhone app development with the iPhone Software Development Kit (SDK) 3.x, the Objective-C® programming language, the Cocoa® frameworks and the Xcode® development tools.

This book presents leading-edge computing technologies for professional software developers. At the heart of the book is our “app-driven approach”—we present concepts in the context of 14 completely coded iPhone apps, rather than using code snippets. The introduction and app test drives at the beginning of each chapter show one or more sample executions. The book’s source code is available at www.deitel.com/books/iPhoneFP/.

Sales of the iPhone and app downloads have been growing explosively. The first-generation iPhone sold 6.1 million units in its initial five quarters of availability.[1] The second-generation iPhone 3G sold 6.9 million units in its first quarter alone. The iPhone 3GS, launched in June 2009, sold 5.2 million units in its first month! At the time of this writing, there were approximately 75,000 apps in the App Store, and in just one year, over 1.5 billion apps were downloaded.[2] The potential for iPhone apps is enormous.

[1] www.apple.com/pr/library/2009/07/21results.html.

[2] www.apple.com/pr/library/2009/07/14apps.html.

iPhone for Programmers was fun to write! We got to know (and love) the iPhone and many of its most popular apps. Then we let our imaginations run wild as we started developing our own iPhone apps. Some of the apps appear in this book, and some we’ll sell through the iTunes App Store. The book’s apps were carefully designed to introduce you to key iPhone features and frameworks (e.g., audio, video, animation, the compass, peer-to-peer connectivity, GPS and much more). You’ll quickly learn everything you’ll need to start building iPhone apps—starting with a test-drive of the Painter app in Chapter 1, then building your first app in Chapter 3. Chapter 2, iPhone App Store and App Business Issues walks you through what makes a great app, the submission process including uploading your apps for consideration by Apple, criteria for approval, what to expect in the process, why Apple rejects apps, deciding whether to sell your apps or offer them for free, and marketing them using the Internet, word-of-mouth, and so on.

Copyright Notice and Code License

This book is copyrighted by Pearson. All of the code and iPhone apps in this book are copyrighted by Deitel & Associates, Inc. As a user of the book, we grant you the nonexclusive right to copy, distribute, display the code, and create derivative apps based on the code for noncommercial purposes only—so long as you attribute the code to Deitel & Associates, Inc. and reference www.deitel.com/books/iPhoneFP/. If you have any questions, or specifically would like to use our code for commercial purposes, contact deitel@deitel.com.

Intended Audience

We assume that you’re comfortable with Mac OS X, as you’ll need to work on a Mac to develop iPhone apps. We also assume that you’re a programmer with significant experience working in a C-based object-oriented language such as Objective-C, C++, Java or C#. If you have not worked in any of these languages, you should still be able to master iPhone app development and object-oriented programming by reading the code and our code walkthroughs, running the apps and observing the results. You’ll quickly learn a great deal about object-oriented iPhone app development in Objective-C and Cocoa. We overview the basics of object-oriented programming in Chapter 1.

Key Features

Here are some of the book’s key features:

App-Driven Approach. You’ll learn the programming technologies in the context of 14 complete working iPhone apps. Each chapter presents one app—we discuss what the app does, show screen shots, test-drive it and overview the technologies and the architecture you’ll use to build it. Then we build the app, present the complete code and do a detailed code walkthrough. As part of the code walkthrough, we discuss the programming concepts and demonstrate the functionality of the iPhone APIs (application programming interfaces). Figure 1 lists the 14 apps in the book and the key technologies we introduce as we present each.

Fig. 1. iPhone for Programmers apps and the technologies they introduce.
iPhone for Programmers apps and the technologies they introduce
Chapter 3, Welcome App Introducing Xcode, Cocoa and Interface Builder

Chapter 4, Tip Calculator App Introducing Objective-C Programming

Chapter 5, Favorite Twitter® Searches App Collections and Cocoa GUI Programming

Chapter 6, Flag Quiz Game App Controllers and the Utility Application Template

Chapter 7, Spot-On Game App Using UIView and Detecting Touches

Chapter 8, Cannon Game App Animation with NSTimer and Handling Drag Events

Chapter 9, Painter App Using Controls with a UIView

Chapter 10, Address Book App Tables and UINavigationController

Chapter 11, Route Tracker App Map Kit and Core Location (GPS and Compass)

Chapter 12, Slideshow App Photos and iPod Library Access

Chapter 13, Enhanced Slideshow App Saving Data and Playing Video

Chapter 14, Voice Recorder App Audio Recording and Playback

Chapter 15, Enhanced Address Book App Managing and Transferring Persistent Data

Chapter 16, Twitter® Discount Airfares App Internet Enabled Applications


Objective-C. This book is not an Objective-C tutorial, but it teaches a good portion of this object-oriented programming language in the context of iPhone app development.

Cocoa Frameworks. Cocoa is the set of frameworks and the runtime environment for the iPhone. Throughout the book, we use many of the Cocoa features and frameworks. (Figure 1.9 in Chapter 1 shows the Cocoa frameworks.)

iPhone SDK 3.x. We cover many of the new features included in iPhone Software Development Kid (SDK) 3.x—the Game Kit framework for Bluetooth peer-to-peer connectivity, the Map Kit framework for embedding Google Maps[3], the Media Player framework for accessing the iPod music library, the Core Location framework for accessing the compass and the Core Data framework for managing app data.

[3] Note: The Route Tracker App uses the Map Kit framework which allows you to incorporate Google™ Maps in your app. Before developing any app using the Map Kit, you must agree to the Google Maps Terms of Service for the iPhone (including the related Legal Notices and Privacy Policy) at: code.google.com/apis/maps/iphone/terms.html.

Xcode. Apple’s Xcode integrated development environment (IDE) and its associated tools for Mac OS, combined with the iPhone SDK, provide everything you need to develop and test iPhone apps.

Instruments. The Instruments tool, which is packaged with the SDK, is used to inspect apps while they’re running to check for memory leaks, monitor CPU usage and network activity, and review the objects allocated in memory. We discuss how we used the Instruments tool to fix memory leaks and performance problems in Chapter 6’s Flag Quiz Game App and Chapter 8’s Cannon Game App, respectively.

Multimedia. The apps use a broad range of iPhone multimedia capabilities, including graphics, images, audio, video, speech synthesis and speech recognition.

iPhone App Design Patterns. This book adheres to Apple’s app coding standards, including the Model-View-Controller (MVC) design pattern. (Figure 1.8 in Chapter 1 shows many of the design patterns we use directly or indirectly in the book.)

Web Services. Web services enable information sharing, e-commerce and other interactions using standard Internet protocols and technologies. Web services allow you to use the web as a library of reusable software components. Chapter 11’s Route Tracker app uses built-in Apple APIs to interact with the Google Maps web services. In Chapter 16’s Twitter® Discount Airfares app, you’ll work directly with Twitter’s REST-based web services.

Uploading Apps to the App Store. In Chapter 2, iPhone App Store and App Business Issues, we walk you through the process of obtaining development certificates, creating provisioning profiles, submitting your apps to the App Store for approval, deciding whether your app should be free or fee based, marketing it and much more.

Features

Syntax Shading. For readability, we syntax shade the code, similar to Xcode’s use of syntax coloring. Our syntax-shading conventions are as follows:

comments appear in gray
keywords appear in bold black
constants and literal values appear in bold gray
all other code appears in black

Code Highlighting. We use gray rectangles to emphasize the key code segments in each program that exercise the new technologies the program presents.

Using Fonts for Emphasis. We place the defining occurrences of key terms in bold italic text for easier reference. We emphasize on-screen components in the bold Helvetica font (e.g., the Project menu) and emphasize Objective-C and Cocoa program text in the Lucida font (e.g., int x = 5;).

In this book you’ll create GUIs using a combination of visual programming (drag and drop) and writing code. We’ll constantly be referring to GUI elements on the screen. We use different fonts when we refer to GUI components. For example, if a button is part of the IDE, we write the word “button” in lowercase and plain text, as in “Build and Go button.” If on the other hand, it’s a button that we create as part of an app, we use the name Button as it appears in the library of controls you can use in an app. When we refer to a Button’s class, we use the class name UIButton.

Source Code. All of the source-code examples are available for download from:

www.deitel.com/books/iPhoneFP/

Documentation. All of the manuals that you’ll need to develop iPhone apps are available free at developer.apple.com/iphone/.

Chapter Objectives. Each chapter begins with a list of objectives.

Figures. Abundant charts, tables, app source code listings and iPhone screen shots are included.

Index. We include an extensive index, which is especially useful when you use the book as a reference. Defining occurrences of key terms are highlighted with a bold page number.

The Deitel Online Resource Centers

Our website www.deitel.com provides more than 100 Resource Centers on various topics including programming languages, software development, Web 2.0, Internet business and open-source projects—see the list of Resource Centers in the first few pages of this book and visit www.deitel.com/ResourceCenters.html. Each week we announce our latest Resource Centers in our newsletter, the Deitel® Buzz Online(www.deitel.com/newsletter/subscribe.html). The Resource Centers evolve out of the research we do to support our publications and business operations. We’ve found many exceptional iPhone and iPhone programming resources online, including tutorials, documentation, software downloads, articles, blogs, podcasts, videos, code samples, books, e-books and more—most of them are free. Check out the growing list of iPhone-related Resource Centers, including:

Deitel® Buzz Online Free E-mail Newsletter

The Deitel® Buzz Online e-mail newsletter will keep you posted on issues related to this book. It also includes commentary on industry trends and developments, links to free articles and resources from our published books and upcoming publications, product-release schedules, errata, challenges, anecdotes, information on our corporate instructor-led training courses delivered at client locations worldwide and more. To subscribe, visit

www.deitel.com/newsletter/subscribe.html

Follow Deitel on Twitter® and Facebook®

To receive updates on Deitel publications, Resource Centers, training courses, partner offers and more, follow us on Twitter®

@deitel

and join the Deitel & Associates group on Facebook®

www.deitel.com/deitelfan/

Acknowledgments

We’re fortunate to have worked on this project with the talented and dedicated team of publishing professionals at Prentice Hall/Pearson. We appreciate the extraordinary efforts and mentorship of Mark L. Taub, Editor-in-Chief of Pearson Technology Group. Sandra Schroeder designed the book’s cover. John Fuller managed the book’s production.

Reviewers

We wish to acknowledge the efforts of our reviewers. Adhering to a tight time schedule, they scrutinized the manuscript and the programs and provided constructive suggestions for improving the accuracy and completeness of the presentation:

  • Marcantonio Magnarapa, Research & Development on Mobile Platforms, Ogilvy Interactive

  • Zach Saul, Founder, Retronyms

  • Rik Watson, Senior Software Engineer, Lockheed Martin

Well, there you have it! This book will quickly get you comfortable developing iPhone apps. As you read the book, we’d sincerely appreciate your comments, criticisms, corrections and suggestions for improvement. Please address all correspondence to:

deitel@deitel.com

We’ll respond promptly, and post corrections and clarifications on:

www.deitel.com/books/iPhoneFP/

We hope you enjoy reading iPhone for Programmers: An App-Driven Approach as much as we enjoyed writing it!

Paul Deitel
Harvey Deitel
Abbey Deitel
Eric Kern
Michael Morgano
October 2009

About Deitel & Associates, Inc.

Deitel & Associates, Inc., founded by Paul Deitel and Harvey Deitel, is an internationally recognized authoring, corporate training and software development organization specializing in computer programming languages, object technology, Internet and web software technology, iPhone app development and training, and Internet business development. The company offers instructor-led courses delivered at client sites worldwide on major programming languages and platforms, such as Objective-C and iPhone app development, C, C++, Visual C++®, Java™, Visual C#®, Visual Basic®, XML®, Python®, object technology, Internet and web programming, and a growing list of additional programming and software-development-related courses. The company’s clients include many of the world’s largest companies, government agencies, branches of the military, and academic institutions. Through its 33-year publishing partnership with Prentice Hall/Pearson, Deitel & Associates, Inc., publishes leading-edge programming professional books, textbooks, LiveLessons DVD- and web-based video courses, and e-content for popular course-management systems. Deitel & Associates, Inc., and the authors can be reached via e-mail at:

deitel@deitel.com

To learn more about Deitel’s Dive Into® Series Corporate Training curriculum, visit:

www.deitel.com/training/

To request a proposal for on-site, instructor-led training at your company or organization, e-mail:

deitel@deitel.com

To learn more about the company and its publications, subscribe to the free Deitel® Buzz Online e-mail newsletter at:

www.deitel.com/newsletter/subscribe.html

Individuals wishing to purchase Deitel books and LiveLessons DVD- and web-based training courses can do so through www.deitel.com. Bulk orders by corporations, the government, the military and academic institutions should be placed directly with Pearson. For more information, visit www.prenhall.com/mischtm/support.html#order.