Introduction

When Apple introduced the iPhone Software Development Kit (SDK) in 2008, the iPhone and iPod touch suddenly became the handheld computers they were meant to be. Interest in the SDK exceeded Apple's expectations — in fact, Apple's servers supplying the beta for the first SDK download were overwhelmed.

Since then, the App Store has grown to become the repository of over 140,000 applications, which collectively are driving innovation beyond the reach of other mobile devices. The success of the App Store — over three billion downloads — has turned the iPhone into the premier mobile device for publishing software. All the leading mobile applications typically appear on the iPhone first, and as a reader of this book, you may be creating the next one.

As I continue to explore the iPhone as a new platform, I keep finding more possibilities for applications that never existed before. The iPhone or iPod touch is a mobile computer, but not like a mobile desktop. Its hardware and software make it possible to wander the world, or your own neighborhood, and stay connected to whomever and whatever you want to. It enables a new class of here-and-now applications that give you access to content-rich services and let you view information about what's going on around you and where you are, and interact with those services or with others on the Internet.

One of the hallmarks of a great iPhone application is that it leverages the iPhone's unique hardware, especially its ability to know where the user is. The iPhone SDK includes tools such as MapKit, which makes it much easier to use the location-based features of the iPhone in an application. MapKit makes it possible for even a beginning developer to take full advantage of the location hardware, and I've included the code for an example app (called RoadTrip) to show you how. And the frameworks supplied in the SDK are especially rich and mature. All you really have to do is add your application's user interface and functionality to the framework, and then "poof" . . . an instant application.

If you're familiar with the first version of the SDK, you're in for a pleasant surprise: The latest version of the SDK, which includes Xcode 3.2.2, is a lot, lot better and easier to use. What's really hard, after you've learned your way around the SDK and its various framework, is figuring out how to create a structure for the iPhone application's data and models for the logic of how the application should work. Although there are lots of resources, the problem is exactly that: There are lots of resources — as in thousands of pages of documentation! You may get through a small fraction of the documentation before you just can't take it anymore and plunge right into coding. Naturally enough, there will be a few false starts and blind alleys until you find your way, but I predict that after reading this book, it will be (pretty much) smooth sailing.

That's why, when the For Dummies folks asked me to combine all the knowledge and wisdom I could muster to write these minibooks on developing software for the iPhone, I jumped at the chance. Here's the definitive tome that I wish I had for a reference myself when I started developing iPhone software.

Editor's note: Both authors (Tony and Neal) have published applications for the iPhone — you can find several of Neal's apps, including ReturnMeTo, in the App Store, along with Tony's app, Tony's Tips for iPhone Users.

About This Book

iPhone Application Development All-in-One For Dummies is more than just a beginner's guide to developing iPhone applications — it's also a concise reference work on programming with Objective-C. And not only do you not need any iPhone development experience to get started, you don't need any Macintosh development experience either. I expect you to come as a blank slate, ready to be filled with useful information and new ways to do things.

Because of the nature of the iPhone, you can create small, bite-sized applications that can be really powerful. And because you can start small and create real applications that do something important for a user, it's relatively easy to transform yourself from "I know nothing" into a developer who, though not (yet) a superstar, can still crank out quite a respectable application.

But the iPhone can be home to some pretty fancy software as well — so I take you on a journey through building an industrial-strength application and show you the ropes for developing one on your own.

This book distills the hundreds (or even thousands) of pages of Apple documentation, not to mention our own development experiences, into only what's necessary to start you developing real applications. But this is no recipe book that leaves it up to you to put it all together; rather, it takes you through the frameworks and iPhone architecture in a way that gives you a solid foundation in how applications really work on the iPhone — and acts as a roadmap to expand your knowledge as you need to.

It's a multicourse banquet, intended to make you feel satisfied (and really full) at the end.

Conventions Used in This Book

This book guides you through the process of building iPhone applications. Throughout, you use the provided iPhone framework classes (and create new ones, of course) and code them with the Objective-C programming language.

Code examples in this book appear in a monospaced font so they stand out a bit better. That means the code looks like this:

#import <UIKit/ UIKit.h>

In addition, code that you need to enter is set in bold, and code you need to delete is set in regular type with a strikethrough, as follows:

#import <UIKit/ UIKit.h> // Add this line to your code

#import <UIKit/  UIKit.h> // Delete this line to your code

Objective-C is based on C, which (I want to remind you) is case-sensitive, so please enter the code that appears in this book exactly as it appears in the text. This book also uses the standard Objective-C naming conventions — for example, class names always start with a capital letter, and the names of methods and instance variables always start with a lowercase letter.

All URLs in this book appear in a monospaced font as well:

www.nealgoldstein.com
www.tonybove.com

If you're ever uncertain about anything in the code, you can always look at the source code on Neal's Web site at www.nealgoldstein.com. From time to time, he provides updates for the code there, and posts other things you might find useful. (You can find a mirror image of Neal's site at www.dummies.com/go/iphoneappdevaio, if you happen to be strolling through the dummies. com site.) Tony offers tips about everything from developing to marketing apps at www.tonybove.com.

Foolish Assumptions

To begin programming your iPhone applications, you need an Intel-based Macintosh computer with the latest version of the Mac OS on it. (No, you can't program iPhone applications on the iPhone.) You'll also need to download the iPhone Software Development Kit (SDK) — which is free — but you do have to become a registered iPhone developer before you can do that. (Don't worry; I show you how in Chapter 3 of Book I.) And, oh yeah, you'll need an iPhone. You won't start running your application on it right away — you'll use the Simulator that Apple provides with the iPhone SDK during the initial stages of development — but at some point, you'll want to test your application on a real, live iPhone (and possibly also an iPod touch).

This book assumes that you have some programming knowledge and that you have at least a passing acquaintance with object-oriented programming, using some variant of the C language (such as C++, C#, or maybe even Objective-C). If not, we point out some resources that can help you get up to speed. The examples in this book are focused on the frameworks that come with the SDK; the code is pretty simple (usually) and straightforward. (I don't use this book as a platform to dazzle you with fancy coding techniques.)

This book also assumes that you're familiar with the iPhone itself and that you've at least explored Apple's included applications to get a good working sense of the iPhone look and feel. It would also help if you browse the App Store to see the kinds of applications available there, and maybe even download a few free ones (as if I could stop you).

How This All-in-One Book Is Organized

iPhone Application Development All-in-One For Dummies has seven minibooks.

Book I: Creating the Killer App

Book I introduces you to the iPhone world and gives you the fundamental background that you need to develop iPhone applications. You find out what makes a great iPhone application, and how an iPhone application is structured. You also find out how to become an "official" iPhone developer and what you need to do in order to be able to distribute your applications through Apple's App Store. You find out how to download the Software Development Kit (SDK) — and then you unpack all the goodies contained therein, including Xcode (Apple's development environment for the OS X operating system) and Interface Builder. (You'll soon discover that the latter is more than your run-of-the-mill program for building graphical user interfaces.) I show how everything works together, which should give you a real feel for how an iPhone application works.

Book II: Objective-C and iPhone Technologies

Book II gives you a rundown on everything you need to know about Objective-C to write iPhone applications. Its focus is on the right way to structure your application — what's known as the program architecture. Having the right architecture results in an application that not only works but also can be extended to add new functionality (relatively) easily. And not only that, it enables you to easily track down and fix those pesky bugs that make their home in everyone's apps. I also show you how to deal with the mundane, but necessary, plumbing issues such as memory management and object initialization. You even find out some of the tricks that programmers use to extend frameworks to offer highly specific functionality.

Book III: Building a Utility App — DeepThoughts

With Objective-C basics behind you and a good understanding of the iPhone application architecture under your belt, it's finally time to have some fun doing something useful. In this minibook, I show you how to create an application that is simple enough to understand and yet demonstrates enough of the building blocks for creating a sophisticated app. I show you how an app fits into the user SDK-supplied frameworks that do all of the user interface heavy lifting on the iPhone. And because you design the app the right way from the start, you can plug it into the user interface with minimal effort by creating the interface in the Interface Builder (part of the SDK) and adding a few lines of code. No sweat, no bother. Putting this handy little app together will give you some practice at creating a useful utility application that allows your application's users to add preferences and settings. It's a great application to learn about iPhone development — it has enough features to be useful as an example, but simple enough not to make your head explode.

Book IV: Debugging and Tuning Your Application

Bugs can show up in your application in different forms and wreak different kinds of havoc with your programming efforts. As the nearly immortal Mr. Spock (the one from the planet Vulcan) once said, "Logic is the beginning of wisdom, not the end." And if Spock ever heard about Murphy's Law (that anything that could go wrong will go wrong), he'd probably reply, "Fascinating!" And yet, debugging is not considered fascinating — often it's something to put off until later, after the warnings and error messages pile up. (Perhaps you recall the classic Star Trek episode, "The Trouble with Tribbles.") This book sets you on the illuminated path of self-debugging. You find out how to recognize bugs in the Xcode editor and, most importantly, what to do about them. You get all the details about how to use the Debugger to track bugs, how to set breakpoints in your code to stop execution and examine the gory details, how to detect memory leaks, and how to fine-tune your app with the Instruments application.

Book V: Building an Industrial Strength Application — RoadTrip!

Book V introduces you to an iPhone application that contains lots and lots of functionality you can borrow for your app. I show you how to design an application with lots of data, views, and access to the Web. I don't go slogging through every detail, but I demonstrate almost all the technology you need to master if you're going to create a compelling application like this on your own. I also touch on a few advanced topics, such as creating self-configuring objects so you don't find your classes multiplying like rabbits.

Book VI: Storing and Accessing Data

Book VI shows you how to deal with data using property lists, the URL Loading System, and Core Data. You learn how to download data for your app from a Web server, so you can update the data at any time and add new information. You also get an in-depth look at using dictionaries to hold property list objects and application objects. This minibook also takes you on a march through an array using a new language feature of Objective-C 2.0 called fast enumeration — starting at the first data element and returning each element for processing — which is an essential function of many applications.

Book VII: Extending the App to the Realm of Ultracool

Book VII takes the RoadTrip app out to the ever-expanding galaxy of iPhone functionality. You find out how to use data from the Contacts app in your app, display the standard e-mail view inside your app to manage editing and sending e-mails, and Core Location to find out exactly where the iPhone is located. At the end of this minibook, you should be ready to go out and conquer the world with your app.

Because the application I develop in Books V–VII has lots of functionality, I won't be able to show you of all of the code in each of the books. But have no fear, because the listings for each minibook are available at www.dummies.com/go/iphoneappdevaio as well as on Neal's Web site at www.nealgoldstein.com.

Icons Used in This Book

Tip

This icon indicates a useful pointer that you shouldn't skip.

Note

This icon represents a friendly reminder. It describes a vital point that you should keep in mind while proceeding through a particular section of the chapter.

Note

This icon signifies that the accompanying explanation may be informative (dare I say, interesting?), but it isn't essential to understanding iPhone application development. Feel free to skip past these tidbits if you'd like (though skipping while leaning may be tricky).

Warning

This icon alerts you to potential problems that you may encounter along the way. Read and obey these blurbs to avoid trouble.

Where to Go from Here

Feel free to begin reading this book anywhere or skip particular minibooks or chapters (or go really wild and start on page 1 and continue reading to the Index). If you want to know how to tackle a particular task, look it up in the Index or Table of Contents and flip to the page you need. This is your book; dive right in.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.190.170