iOS Recipes
Tips and Tricks for Awesome iPhone and iPad Apps
by Matt Drance, Paul Warren
Version: P1.0 (July 2011)
Copyright 2011 Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trust-don't allow othersto use your copy of the book. Thanks.
- Dave & Andy.
Table of Contents
Copyright 2011, The Pragmatic Bookshelf.
What Readers Are Saying About iOS Recipes
If I had to pick just one person to learn from, to learn the best ways to do things in iOS, it would be Matt Drance. And the book doesnt disappoint. I made use of a couple recipes immediately, and I look forward to using more of them, especially Pauls fun graphics and animation recipes!
Brent Simmons |
Developer, NetNewsWire |
iOS Recipes is the book that commonly answers the How did they do that? question. It is an essential book for anyone who wants to sprinkle little bits of awesome in their app.
Justin Williams |
Crew chief, Second Gear |
This is a great book for both beginners and experienced developers. Its packed with useful up-to-date examples showing how to add professional-grade features to your projects, with great explanations and a focus on the code.
Michael Hay |
Master developer, Black Pixel LLC |
I highly recommend this book. So many of these tips and tricks, aka recipes, get lost or become difficult to find. I would rather pull a book off the shelf (or iBooks) and look for that snippet of code I knew I saw in there rather than search the Internet in hope that the site I saw it on still has it. This book will definitely be in that collection.
Marcus S. Zarra |
Owner, Zarra Studios LLC |
If you use just one of these recipes in your app, that alone is worth the price of this book. I quickly lost count of the recipes that I found immediately useful. If youre getting paid to write iOS apps, or you just value your time, youd be crazy not to have this book within arms reach at all times.
Mike Clark |
Founder, Clarkware |
Foreword
iOS is an amazing platform to develop for. Its incredible touch screen and interaction paradigms have opened up entirely new categories of applications. Weve already seenbrilliant developers come up with software we could have barely imagined a few short years ago. The portability of the iPhone, iPod touch, and iPad means that we take themeverywhere with us, and their reasonable battery life means that we use them constantly. Quite simplyand with apologies to the 2007 vintage MacBook Pro running Snow Leopard that Idevelop software and process my photos withiOS is pointing the way to the future. Its obvious that computing has changed and wont be going back to the way it was in 2005.
Heady stuff, that. Who wouldnt want to develop software for these amazing devices?
On the other hand, the reality is that weve had only a few short years to start learning how to best develop software for the iOS and its touch-based frameworks. Sure, some ofyou have been creating software for Mac OS X and have a bit of a head start over the vast majority of you who have come to iOS development from other platforms. Make no mistake,however. No matter what your background, we all find ourselves in a new land when it comes to writing for iOS. Even though I wrote my first Cocoa app more than a decade ago and havewritten more than my share of books and articles on Mac OS X development, Ive had more than a few head-scratching sessions as Ive worked with iOS and dove through itsdocumentation in Xcode. Theres so much to figure out, including how to create perfect splash screens, how to make table and scroll views do our bidding most efficiently, how to access themany network services modern social applications use, and how to work with the iOS runtime instead of fighting against it.
Luckily, we dont have to sort all of these things out on our own. Matt and Paulthe authors of this bookhave assembled a set of examples and incorporated the latest, mostcurrent iOS software development best practices in this book of recipes. The result gives you a great set of specific solutions to targeted problems that you can dip in and outof as the need arises.
Its better than that, however. Even though this book is a collection of discrete sections that can stand on their own quite well, reading straight through them all gives morethan a few valuable insights into how Matt and Paul approach their craft. As I read through a beta draft of the book myself, it felt much the same as watching some of my favoritechefs making good food in their kitchen and learning from the way they approached the task at hand, even the simple tasks that I thought I already had mastered.
So, pull up a chair. Join two of my favorite iOS developers and learn a few things. Then, go out and make the kind software you could only dream about a few years ago.
James Duncan Davidson
April 2011
Copyright 2011, The Pragmatic Bookshelf.
Introduction
Your goal as a programmer is to solve problems. Sometimes the problems are hard, sometimes theyre easy, and sometimes theyre even fun. Maybe theyre not even problems in the colloquial sense of the word, but you are there to discover solutions.
Our goal as authors is to help you solve your problems better and more quickly than beforepreferably in that order. We decided to write a recipe-style book that focuses on a specific set of tasks and problems that we attack explicitly, rather than discuss programming issues at a high level.
Thats not to say were not about educating in this book. The blessing of a recipe book is that it gives you trustworthy solutions to problems that you dont feel like discovering on your own. The curse of a recipe book is that you might be tempted to copy and paste the solutions into your project without taking the time to understand them. Its always great to save time by writing less code, but its just as great to think and learn about how you saved that time and how you can save more of it moving forward.
If you are familiar with the iOS SDK and are looking to improve the quality and efficiency of your apps, then this book is for you. We dont teach you how to write apps here, but we hope that this book helps you make them better. If youre more of an advanced developer, you may find that you save yourself time and trouble by adopting some of the more sophisticated techniques laid out in the pages that follow.
We wrote many of these recipes with maximum reusability in mind. We werent after demonstrating a technique or a snippet of code that simply gets the job done. Instead, we set out to build solutions that are ready for you to integrate into whatever iPad and iPhone projects youre working on. Some might find their way into your projects with zero changes, but you should feel free to use this recipe book as you would a traditional cookbook. When cooking food from a recipe, you might add or remove ingredients based on what you like, or need, in a meal. When it comes to your own apps and projects, this book is no different: you are invited to extend and edit the projects that accompany these recipes to fit your specific needs.
The recipes in this book help you get from start to finish, but we hope they also encourage you to think about when and why to choose a certain path. There are often multiple options, especially in an environment like Cocoa. With multiple options, of course, come multiple opinions. In the interest of consistency, we made some decisions early on about certain patterns and approaches to use in this book. Some of these techniques may be familiar to you, some may be employed in a way you hadnt considered, and some may be brand new to you. Regardless, wed like to explain some of our decisions up front so that there are no surprises.