ebook img

iPhone App Development: The Missing Manual PDF

342 Pages·2010·2.89 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview iPhone App Development: The Missing Manual

iPhone App Development THE MISSING MANUAL The book that should have been in the box®ˇ iPhone App Development Craig Hockenberry Beijing  •  Cambridge  •  Farnham  •  Köln  •  Sebastopol  •  Taipei  •  Tokyo iPhone App Development: The Missing Manual by Craig Hockenberry Copyright © 2010 Craig Hockenberry. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly Media books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles: my.safaribooksonline.com. For more information, contact our corporate/institutional sales department: 800-998-9938 or [email protected]. May 2010: First Edition. The Missing Manual is a registered trademark of O’Reilly Media, Inc. The Missing Manual logo, and “The book that should have been in the box” are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media is aware of a trademark claim, the designations are capitalized. While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained in it. This book uses a durable and flexible lay-flat binding. ISBN: 9780596809775 [M] Table of Contents The Missing Credits . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Part One: Getting Started with Cocoa Touch Chapter 1: Building Your First iPhone App . . . . . . . . . . . . . . 9 Getting the Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Installing Xcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Getting the iPhone SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 What Lies Ahead for the SDK? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Exploring Your New Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Every Flashlight Needs a Parts List . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Some Assembly Required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Taking It for a Run on Your Mac . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Revision Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Chapter 2: The Power of Brackets . . . . . . . . . . . . . . . . . . 29 Objective-C: The Nuts and Bolts for Your iPhone App . . . . . . . . . . . . . . . . . . . . 30 The Land of Square Brackets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 The Object of It All . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Telling Your Objects to Do Things . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Masses of Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Classes in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 The Methods Behind the Madness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Categorically Speaking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Implementation: The Brains Behind the Beauty . . . . . . . . . . . . . . . . . . . . . 39 Creating New Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 v Managing Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Take a nil Pill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Autorelease with Ease . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Properties and Dots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Methods of Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Initializing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Deallocation Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Loops: For Better or For Worse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Your Exceptional Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Learn by Crashing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Selector Projector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Show Your id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Developer Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Learn to Be Lazy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Chapter 3: Cocoa Touch: Putting Objective-C to Work . . . . . . 65 Get in Cocoa Touch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 The Big Three: Models, Views, Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Value Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Let’s Get Primitive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Objectified . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Copying in Depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Property Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Mutable Versus Immutable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Make It Mutable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Protect Your Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Delegation and Data Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Targets and Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 User Interface: The Hard Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 User Interface: The Easy Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Singletons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Singletons as Globals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 The Language of Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Chapter 4: Design Tools: Building a Better Flashlight . . . . . . . 103 Plan Before You Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Why Call in a Designer? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Design Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 What’s Unique about iPhone Design? . . . . . . . . . . . . . . . . . . . . . . . . . 105 vi table of contents The Design Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Living in Harmony with Your Designer . . . . . . . . . . . . . . . . . . . . . . . . . 111 Feedback: Don’t Take Your Own Word for It . . . . . . . . . . . . . . . . . . . . . . . . 113 The Providers of Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Flashlight 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Bigger, Stronger, Faster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 The Light Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 The Flip Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 The Drawing Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Technical Design: Between Pictures and Code . . . . . . . . . . . . . . . . . . . . . . . 118 Start Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Ready to Code! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Part Two: Development in Depth Chapter 5: Getting Serious about Development . . . . . . . . . . 125 Beyond the Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Pick Your SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Change Project Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Change Target Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Build Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Duplicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Make It Official . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Join the iPhone Developer Program . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Open the Door . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 When It Fails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 You’re Now Mobile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Ready to Roll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Chapter 6: A Flashlight for Pros . . . . . . . . . . . . . . . . . . . . 155 A Guided Tour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Where to Start? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Open the Guide Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Flashlight_ProAppDelegate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 NIB Files: Something to Look At . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 MainWindow.xib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 MainView.xib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 View Sizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Autoresizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 SettingsView.xib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 AboutView.xib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Refine the Look . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 LightView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 IFInfoView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 table of contents vii Making Cocoa Touch Your Own . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 UIColor+Brightness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 UIView+Brightness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 UIView+Concealed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Fashion Your Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 SOSModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 FlashlightModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Pull Yourself Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 MainViewController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 SettingsViewController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 AboutViewController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Localized Languages: Capisce? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 Localizable.strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 AboutView.xib . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Wrapping It Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Part Three: The Business End Chapter 7: Finishing Touches . . . . . . . . . . . . . . . . . . . . . . 213 Beta Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Your App Works for You…But . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Ad Hoc & Roll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Clean Up Your Act . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Beautification Committee . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 Speaking in Tongues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 Web Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 The Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 App Store, Here You Come . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Chapter 8: For Sale . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Sign on the Dotted Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Welcome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 First Order of Business . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Stake Your Claim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Export Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Ratings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Upload—Show It Off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Pricing—Pick Your Price . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Tweak It . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 viii table of contents

Description:
Anyone with programming experience can learn how to write an iPhone app. But if you want to build a great app, there's a lot more to it than simple coding: you also need to know how design and market your creation. This easy-to-follow guide walks you through the entire process, from sketching out yo
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.