About this book

iPhone in Action is an introductory book, intended to teach the basics of iPhone programming in a tutorial form. It covers the fundamentals of both major styles of programming for the platform: web development and SDK programming.

You can read this book in one of three ways.

We encourage you to read it straight through, from chapter 1 to 20. This will introduce the platform, introduce both major ways to program for the iPhone, offer advice on when one style of programming is more appropriate than the other, and step you through both styles in turn.

If you prefer to read only about web development, you can just read parts 1 and 2. Note that we’ve included an introduction to Objective-C at the end of part 2 that will get you started on iPhone SDK programming, even if you’ve never used a compiled programming language before, so we encourage you to keep on going, and see what else you can learn.

If you prefer to read only about SDK programming, you can just read parts 1, 3, and 4. We still encourage you to at least skim the chapters in part 2, because they include advice especially for SDK programmers, showing how lessons learned from the web can apply to the SDK as well.

The audience

This is an introductory book. We’ve done our best to make it accessible to everyone who might be interested in developing web pages or writing native programs for the iPhone. We think that it’ll be especially useful to people who are looking to wholeheartedly dive into the iPhone arena, because it will allow you to choose whether to write web apps or create native applications for each and every project that you work on.

If you want to learn about iPhone web development, you should have a good understanding of web design in general, including HTML, CSS, and JavaScript. You don’t need to know any more dynamic languages to create great iPhone web apps. In fact, Apple’s powerful Dashcode development platform is built entirely using these three languages.

If you want to learn about iPhone SDK programming, you should have some experience with programming in general. It’d be best if you’ve worked with C before, but that’s not a necessity; if you haven’t, you can read our introduction to C in chapter 9, and you should probably expect to do some research on your own to clarify things. There’s definitely no need to be familiar with Objective-C, Cocoa, or Apple programming in general. We’ll give you everything you need to become familiar with Apple’s unique programming style. You’ll probably have a leg up if you understand object-oriented concepts, but again it’s not necessary (and again, you’ll find an introduction in chapter 9).

Roadmap

We’ve divided this book into four parts, with one covering introductory iPhone concepts, one covering web development, and two covering SDK programming.

Part 1 introduces the iPhone and the styles of programming that are possible for this device.

Chapter 1 explains the details of the iPhone and how it differs from the mobile phones that predated it. It also contains one of our most important concepts: the six unique features that truly make the iPhone stand out from the pack, and which are also of importance to programmers.

Chapter 2 describes the two styles of iPhone programming—web development and SDK programming—and discusses the strengths of each, so that you can make an informed decision about how to program any individual application. It also briefly touches upon the idea of hybridizing the two styles of iPhone programming.

Part 2 includes all of our information about writing and rewriting web pages for use on the iPhone.

Chapter 3 presents the basics of what you can do to redevelop an existing web page for viewing on the iPhone. In the process, it touches upon many of the most important factors concerning iPhone web pages, such as the viewport, the technology limitations, and the event changes.

Chapter 4 covers the first of three web libraries for use on the iPhone. The WebKit is an extension to HTML being worked on by Apple that gives you access to a variety of great features, from implicit animations to a built-in database.

Chapter 5 discusses the issue of how to make web pages that match the look and feel of iPhone native applications. In the process, it introduces a second notable web library, iUI, which creates iPhone-like animations and tables from simple HTML.

Chapter 6 focuses on the third of our iPhone web libraries, Canvas, another HTML extension championed by Apple. This graphical library gives you the ability to draw complex vector graphics and display them on the iPhone.

Chapter 7 turns to Dashcode, an Apple development environment that you can use to create iPhone web apps. With Dashcode’s integrated links to the WebKit and Canvas, you can use the lessons of the previous chapters while working in a graphical layout program.

Chapter 8 finishes off our look at web development by touching upon how you can test and debug your iPhone web apps, using a variety of third-party utilities.

Chapter 9 offers a bridge, providing an introductory look at the tools that will be useful for programming in Objective-C, including the C language, the object-oriented paradigm, and the MVC architectural model.

Part 3 introduces the SDK by covering all of the fundamental topics that you’ll need in order to program native apps for the iPhone.

Chapter 10 kicks things off by highlighting Objective-C, which is the programming language used on the iPhone, and the iPhone OS, an immense collection of frameworks that make many complex tasks very easy.

Chapter 11 looks at Xcode, the first major tool in the SDK. This integrated development environment does more than just compile your code. It also helps you correct simple errors as you type and provides quick, integrated access to all the iPhone programming documents.

Chapter 12 shifts the focus to Interface Builder, a graphical design environment that allows you to create and place interface objects without writing a single line of code. Interface Builder is a powerful time-saver for programmers and is used throughout the rest of the text as a result.

Chapter 13 covers simple view controllers. The basic view controller is an important building block of the MVC paradigm, dividing control from view, while the table view controller provides an easy way to organize information while matching the standard iPhone look and feel.

Chapter 14 steps back to talk about user interaction. It covers events, which users generate by touching the screen with one or more fingers, and actions, which happen when users interact with a control object like a button or a slider.

Chapter 15 finishes our look at view controllers by examining two more advanced possibilities. The tab bar view controllers allows for modal selection between multiple pages of content, and the navigation view controller adds hierarchy to tables.

Part 4 completes our look at the iPhone by opening up the SDK’s toolkit and examining many different features that may be of interest to programmers. At the same time, it also provides more complex programming examples, which should help programmers to develop full-length iPhone projects.

Chapter 16 opens up the SDK toolkit by talking about data. This includes user input, such as actions and preferences; data storage, such as files and databases; and tools that combine input and storage, such as the iPhone’s address book.

Chapter 17 highlights two of the most unique features on the iPhone, the accelerometer and the GPS, showing how the iPhone can track movement through space.

Chapter 18 covers another of the iPhone’s strengths—media—by showing how to do basic work with pictures, movies, and sounds

Chapter 19 provides an extensive look at graphics, centering on the iPhone’s vector graphic language, Quartz 2D. It also offers a brief overview of Core Animation and touches upon OpenGL for the iPhone.

Chapter 20 concludes our tour through the iPhone’s toolkit by examining how it can be used to interact with the Internet. This chapter moves through the entire hierarchy of Internet communication, from low-level host connections to URLs, from web views to modern social languages like XML and JSON.

The appendixes contain some additional information that didn’t fit with the flow of the main text. Appendix A contains a list of SDK objects and what they do. Appendix B features links for many web sites of note for iPhone programming. Appendix C includes the current information on how to deploy your SDK programs to actual iPhones.

Code conventions and downloads

Code examples appear throughout this book. Longer listings will appear under clear listing headings, and shorter listings will appear between lines of text. All code is set in a special font to clearly differentiate it. Class names have similarly been set in our code font; if you might type it into your computer, you’ll be able to clearly make it out.

With the exception of a few cases of abstract code examples, all code snippets began life as working programs. Our complete set of programs can be found at http://www.manning.com/iPhoneinAction. There should be two ZIP files there, one each for the web and the SDK programs. We encourage you to try out the programs as you read; they’ll often include additional code that doesn’t appear in the book and will provide more context. In addition, we feel that actually seeing a program working can greatly elucidate the code required to create it.

Our code snippets in this book all include extensive explanations. We have often included short annotations beside the code, and sometimes we have numbered cue-balls beside lines of code, linking the subsequent discussion to the code lines.

In part 2 of the book, all code snippets are basic HTML (with CSS or JavaScript, as appropriate). In the few places where we used PHP as an example of a more dynamic language, we clearly noted it with <? ?> brackets. In parts 3 and 4 of the book, all code snippets are Objective-C. We’ve usually left header files out of parts 3 and 4, as they tend to be quite basic.

In a few cases in this book, we’ve included content from multiple files in a single listing in order to provide a bigger picture of the program. In these situations, we’ve divided the contents of the different files within a single listing like this: ::: file #1 :::

Software requirements

There are no particular requirements for most of the web portion of this book. You just need to be able to design and deploy web pages. However chapter 7 (on Dashcode) and portions of chapter 8 (particularly the discussion of the iPhone Simulator) refer to software that is available only on a Macintosh.

A Macintosh is absolutely required to do SDK development. You’ll also need to have the iPhone SDK, but this is freely downloadable as soon as you sign up with Apple, as is described in chapter 10.

Authors online

This book is intended to be an introduction to iPhone programming. Though it covers an extensive amount of information on the iPhone, there’s a lot that we couldn’t talk about in a single book. Feel free to come chat with the authors online about additional iPhone topics.

Our main hangout is http://iphoneinaction.manning.com. This blog contains the newest noteworthy links we have found, discussions on “missing classes” that we didn’t cover in this book, and occasional articles of more weight.

There is also an Author Online forum where you can post comments and ask questions of other readers as well as of the authors at http://www.manning.com/iPhoneinAction.

And we continue to host Christopher’s original iPhone forum on web development, which can be found at http://www.iphonewebdev.com.

About the title

By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering. According to research in cognitive science, the things people remember are things they discover during self-motivated exploration.

Although no one at Manning is a cognitive scientist, we are convinced that for learning to become permanent it must pass through stages of exploration, play, and, interestingly, retelling of what is being learned. People understand and remember new things, which is to say they master them, only after actively exploring them. Humans learn in action. An essential part of an In Action guide is that it is example-driven. It encourages the reader to try things out, to play with new code, and explore new ideas.

There is another, more mundane, reason for the title of this book: our readers are busy. They use books to do a job or to solve a problem. They need books that allow them to jump in and jump out easily and learn just what they want just when they want it. They need books that aid them in action. The books in this series are designed for such readers.

About the cover illustration

The illustration on the cover of iPhone in Action is captioned “Russian, Prince of the Cherkeeses.” The Cherkess people are an ethnic group living in the Caucus region of Russia. The illustration is taken from the 1805 edition of Sylvain Maréchal’s four-volume compendium of regional and national dress customs and uniforms. The colorful variety of Maréchal’s collection reminds us vividly of how culturally apart the world’s towns and regions were just 200 years ago. Isolated from each other, people spoke different dialects and languages and their place of origin and their station in life were easy to identify—by their language and by their dress.

Dress codes have changed since then and the diversity by region, so rich at the time, has faded away. It is now hard to tell apart the inhabitants of different continents, let alone different regions or countries. Perhaps we have traded cultural diversity for a more varied personal life—certainly a more varied and faster-paced technological life.

At a time when it is hard to tell one computer book from another, Manning celebrates the inventiveness and initiative of the computer business with book covers based on the rich diversity of regional life of two centuries ago, brought back to life by Maréchal’s pictures.

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

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