Preface

The arrival of the iPhone changed everything. Or, at the very least, it changed the direction of software development for mobile platforms, which is a pretty big thing. It has spawned an entire generation of copycat devices and brought an entire multibillion-dollar industry to its knees. Despite this, it still fits in your pocket.

Third Edition

There have been a lot fewer changes between the release of iOS 5 and iOS 6 than between the release of iOS 3 and iOS 5, especially since changes to Xcode 4 have now slowed as it has matured. Consequently the changes here in the third edition are less sweeping than they were in the second. Nonetheless, the book you now hold in your hands has been updated to reflect the changes Apple has made to Xcode to support the arrival of the iPhone 5 and iOS 6, as well as discussing the changes in iOS 6 that seemed interesting or relevant to mention as part of a introductory title.

Notes from the Second Edition

The changes made in the second edition reflected the fact that a lot had happened since the first edition was published: the release of the iPad, a major release of Xcode, two revisions of the operating system itself, and the arrival of Apple’s iCloud. That book had therefore been refreshed, renewed, and updated to reflect these fairly fundamental changes to the platform, and all of the example code was rewritten from the ground up for Xcode 4 and iOS 5 using ARC.

Who Should Read This Book?

This book gives a rapid introduction to programming for the iPhone, iPod touch, and iPad for those with some programming experience. If you are developing on the Mac for the first time, drawn to the platform because of the iPhone, or alternatively are an experienced Mac programmer making the transition to the iOS, this book is for you.

What Should You Already Know?

The book assumes some knowledge of C, or at least passing knowledge of a C-derived language. Additionally, while I do give a crash course, some familiarity with object-oriented programming concepts would be helpful.

What Will You Learn?

This book will guide you through developing your first application for the iOS from opening Xcode for the first time to submitting your application to the App Store. You’ll learn about Objective-C and the core frameworks needed to develop for the iOS by writing applications that use them, giving you a basic framework for building your own applications independently.

What’s in This Book?

Here’s a short summary of the chapters in this book and what you’ll find inside:

Chapter 1, Why Go Native?
This chapter discusses the need for native applications and compares building native applications to building web applications.
Chapter 2, Becoming a Developer
This chapter walks you through the process of registering as an iOS developer and setting up your work environment, from installing Xcode and the iOS SDK to generating the developer certificates you’ll need to build your applications and deploy them onto your own iPhone, iPod touch, or iPad.
Chapter 3, Your First iOS App
This chapter allows you to get hands-on as quickly as possible and walks you through building your first Hello World application, including how to deploy and run the application on your iPhone, iPod touch, or iPad.
Chapter 4, Coding in Objective-C
This chapter provides a crash course in the basics of the Objective-C language, and if you’re familiar with another C-derived language (and perhaps with object-oriented programming), it should be enough to get you up and running with Objective-C and the Cocoa Touch frameworks.
Chapter 5, Table View-Based Applications
The UITableView and associated classes are perhaps the most commonly used classes when building user interfaces for iOS applications. Due to the nature of the applications, these classes can be used to solve a large cross section of problems, and as a result, they appear almost everywhere. In this chapter, we dive fairly deeply into the table view classes.
Chapter 6, Other View Controllers
After discussing the table view controller in detail, we discuss some of the other view controllers and classes that will become useful when building your applications: simple two-screen views, single-screen tabbed views, modal view controllers, and a view controller for selecting video and images.
Chapter 7, Connecting to the Network
This chapter discusses connecting to the Internet, browsing the Web, sending email, and retrieving information.
Chapter 8, Handling Data
This chapter discusses how to handle data input, both from the application user and programmatically, and how to parse XML and JSON documents. The chapter also covers storing data in flat files and storing data with the SQLite database engine.
Chapter 9, Using Sensors
This chapter discusses how to determine what hardware is available and illustrates how to deal with the major sensors on iOS devices: the accelerometer, magnetometer, camera, and GPS.
Chapter 10, Geolocation and Mapping
This chapter walks you through the process of building applications that make use of the Core Location and MapKit frameworks.
Chapter 11, Introduction to iCloud
This chapter provides a brief introduction to integrating Apple’s iCloud service into your own applications. iCloud is a service that helps you synchronize your data across devices, making documents and data available to all of your subscribed devices.
Chapter 12, Integrating Your Application
This chapter shows you some of the tricks to integrate your application with iOS’s software ecosystem, how to present user preferences with Settings Bundles, and how to use custom URL schemes to launch your application. It also discusses how to make use of the Media Player and Address Book.
Chapter 13, Distributing Your Application
This chapter talks about how to add some final polish to your application and walks you through the process of building your application for distribution, either via ad hoc distribution or for the App Store.
Chapter 14, Going Further
This chapter provides a collection of pointers to more advanced material on the topics we covered in the book, as well as material covering some of those topics that we didn’t manage to talk about in the book.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords
Constant width bold
Shows commands or other text that should be typed literally by the user
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context

Note

This icon signifies a tip, suggestion, or general note.

Warning

This icon signifies a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, if this book includes code examples, you may use the code in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Learning iOS Programming (3rd ed) by Alasdair Allan. Copyright 2013 Alasdair Allan, 978-1-44935-934-8 (O’Reilly).”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://oreil.ly/learn-ios-programming-3e. Supplementary materials are also available at http://www.learningiosprogramming.com/.

To comment or ask technical questions about this book, send email to .

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business. Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.

Acknowledgments

Books do not write themselves, especially the third editions, and especially the third edition of your first book. After fixing everything you felt was wrong with it in the second edition, at least to your own satisfaction, the prospect of doing it all again to keep up with moving technology is daunting. It’s a horrifying prospect, and a harder job than just sitting down and writing a new book from scratch. I’d therefore like to thank my editors, Brian Jepson and Shawn Wallace, for prodding and poking until I actually picked up the manuscript once more and wrote something. I’d also like to thank my long-suffering wife, Gemma Hobson. I’m not entirely sure why she lets me keep writing; it’s almost certainly nothing to do with the royalty checks. Finally to my son Alex, who is still young enough that he’s not entirely sure what Daddy is doing, although he’s moved on a fair way since the first edition was written and can now read and write a few words of his own. Sorry for being so grumpy while I went about the whole business.

Get Learning iOS Programming, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.