Thông tin tài liệu
www.it-ebooks.info
www.it-ebooks.info
What readers are saying about
iOS SDK Development
Being a successful iOS developer means maintaining laser-like focus on the details
that are specific to your app. The best way to do this is to write as little code as
possible. Apple’s frameworks provide an incredible starting point, but you have
to understand what they do, how they work, and why they’re designed the way
they are. I can scarcely think of anyone more qualified to teach you the ins and
outs of Apple’s iOS SDK than Bill Dudney and Chris Adamson. Their all-new,
updated book, iOS SDK Development, is a must-read, plain and simple.
➤
John C. Fox, Creator of MemoryMiner and Co-Host, iDeveloper Live
A programmer looking to branch out into iPhone or iPad development couldn’t
ask for a better guide to getting started. Chris and Bill are excellent teachers, and
that really comes through in these pages.
➤
Dave Klein, Founder of CocoaConf and Author of Grails: A Quick-Start Guide
Never have I read an iOS book that so thoroughly guides the reader through the
development cycle of an iOS app. I recommend this book to anyone learning the
iOS platform.
➤
Jeffrey Holland
In short, this is one of the best iOS books I have read. It might require some outside
homework for someone totally new to programming, but most people coming to
iOS will be existing developers (like me) that are getting sick of PHP and .NET.
➤
Joel Clermont
www.it-ebooks.info
iOS SDK Development
Chris Adamson
Bill Dudney
The Pragmatic Bookshelf
Dallas, Texas • Raleigh, North Carolina
www.it-ebooks.info
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 The Pragmatic
Programmers, LLC was aware of a trademark claim, the designations have been printed in
initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer,
Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade-
marks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes
no responsibility for errors or omissions, or for damages that may result from the use of
information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create
better software and have more fun. For more information, as well as the latest Pragmatic
titles, please visit us at
http://pragprog.com
.
The team that produced this book includes:
Brian P. Hogan (editor)
Potomac Indexing, LLC (indexer)
Molly McBeath (copyeditor)
David J Kelly (typesetter)
Janet Furlow (producer)
Juliet Benda (rights)
Ellie Callahan (support)
Copyright © 2012 The Pragmatic Programmers, LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form, or by any means, electronic, mechanical, photocopying,
recording, or otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-13: 978-1-934356-94-4
Encoded using the finest acid-free high-entropy binary digits.
Book version: P1.0—November 2012
www.it-ebooks.info
Contents
Acknowledgments . . . . . . . . . . . ix
Introduction . . . . . . . . . . . . xiii
1. Tweetings and Welcome to iOS 6 . . . . . . . . 1
Tooling Up 11.1
1.2 Our First Project 2
1.3 Building Our User Interface 8
1.4 Coding the App 14
1.5 Tweet, Sweet Success 24
2. Programming for iOS . . . . . . . . . . 27
Introducing Objective-C 272.1
2.2 Methods and Messaging 28
2.3 Memory Management 30
2.4 Managing an Object’s Properties 31
2.5 Auto Layout and the iPhone 5 36
2.6 The iOS Programming Stack 44
2.7 Building Views with UIKit 45
2.8 Using the Foundation Classes 47
2.9 Internationalization 50
2.10 Wrap-Up 53
3. Asynchronicity and Concurrency . . . . . . . 57
Encapsulating Concurrent Code with Blocks 573.1
3.2 Grand Central Dispatch 61
3.3 Concurrency and UIKit 62
3.4 Sorting with Blocks 70
3.5 Wrap-Up 75
www.it-ebooks.info
4. View Controllers . . . . . . . . . . . . 77
Practicing MVC 784.1
4.2 Working with a View’s Life Cycle 85
4.3 Building a Detailed Recipe View 88
4.4 Wrap-Up 93
5. Table Views . . . . . . . . . . . . . 95
The UITableView 955.1
5.2 Displaying a List of Recipes 96
5.3 Editing a Table 102
5.4 Working with Cell Styles 109
5.5 Recipe Details 111
5.6 Wrap-Up 115
6. Storyboards and Container Controllers . . . . . . 119
Laying Out Storyboards 1196.1
6.2 Using Container Controllers 128
6.3 Moving Around with Navigation Controllers 129
6.4 Managing View Controllers in Navigation Controllers 131
6.5 Transferring App Control and Data 134
6.6 Returning App Control and Data 149
6.7 Wrap-Up 152
7. Documents and iCloud . . . . . . . . . . 155
Making Recipes Persist 1557.1
7.2 Telling the Recipe Document About Edits 163
7.3 Sharing Recipes 169
7.4 Opening Shared Recipe Documents 178
7.5 Storing Documents in iCloud 182
7.6 Wrap-Up 187
8. Drawing and Animating . . . . . . . . . . 189
Drawing Images 1908.1
8.2 Drawing Paths 194
8.3 Using Shadows 197
8.4 Rotating and Animating Images 199
8.5 Drawing Shadows 202
8.6 Wrap-Up 205
9. Testing and Fixing Apps . . . . . . . . . 207
Unit Testing 2079.1
9.2 Debugging Our App 217
Contents • vi
www.it-ebooks.info
9.3 User Interface Testing 219
9.4 Testing Performance with Instruments 228
9.5 Wrap-Up 230
10. The App Store and Beyond . . . . . . . . . 233
Protecting Our Code with Source Control 23310.1
10.2 Running on the Device 239
10.3 Submitting Apps for Review 249
10.4 After We Ship 254
10.5 Onward! 257
A1. Wait! I Forgot (or Never Learned) C! . . . . . . . 259
A1.1 C: The Basics 259
A1.2 Pointers 261
A1.3 Dynamic Memory Management 263
Bibliography . . . . . . . . . . . . 267
Index . . . . . . . . . . . . . . 269
Contents • vii
www.it-ebooks.info
Acknowledgments
This book starts with all the people who asked for it. The relevance and
accuracy of our previous edition, iPhone SDK Development, diminished as
Apple piled on language innovations like blocks, tool changes like Xcode 4,
and all sorts of neat stuff to play with. Readers of the first edition wondered
when we’d get an update out, or they’d send us screenshots of Xcode 4 and
say, “How do I make my windows look like the screenshots in your book?” It
didn’t take long for us to think that our old book was doing a disservice to
new readers and cried out for a up-to-date do-over.
Writing a book is a huge undertaking. But of course it’s not just the authors
that worked hard. Our editor, Brian Hogan, was an invaluable partner in the
tasks of bringing this book home with just the right amount of encouragement
and chiding to get us over the hump and of rescuing this book when we were
foolishly targeting two different audiences and not reaching either of them.
So thanks to Brian for his work throughout this process and converting
sometimes-messy prose into something our readers could understand.
We have a number of individual thanks to hand out in this edition. Jonathan
Penn turned us onto UI Automation testing (covered in Section 9.3, User
Interface Testing, on page 219) with his talks at CodeMash and CocoaConf,
which is no small feat given our long-held skepticism about the testability of
GUIs.
1
Graham Lee tipped us off to Xcode 4.3’s undocumented support for
command-line testing, though we couldn’t get it running as well as we’d like
—maybe in Xcode 5. Finally, we couldn’t write a sidebar called “Don’t Ship
Programmer Art” (in Chapter 10, The App Store and Beyond, on page 233) and
then post iTunes Connect screenshots with our own ugly handmade icon for
the sample Recipes app, so we brought in Scott Ruth of Brave Bit App Studio
to bring the bling.
2
He’s a designer-turned-programmer (with the help of the
1.
http://cocoamanifest.net
2.
http://www.bravebit.com
report erratum • discuss
www.it-ebooks.info
Pragmatic Studio’s iOS programming courses), and you’ll see his pixels near
the end of the book.
From Chris Adamson
It’s been comfortable working again with the Prags and their innovative and
practical publishing system. Building—and more importantly, updating—pro-
gramming books with this system is a breeze, and writing markup is second
nature to developers like us. For what it’s worth, I wrote a bunch of my stuff
on an iPad at a standing desk with a dock keyboard and the Textastic app
(
http://www.textasticapp.com
). It’s inspiring to think that we’re writing about how
to build the tools we use every day; maybe someone reading this book will
write my next favorite app.
I’m grateful to my family for putting up with both my absence and my stress
through one more book and to all the readers of the first edition who wrote
in or posted on the forums as they got their first apps up on the store. That’s
the kind of thrill that keeps us going.
Obligatory end-of-book tune check: this time it was Sarah Slean, Rich Aucoin,
Coeur de Pirate, Fitz and the Tantrums, and Metric. Up-to-date stats at
http://www.last.fm/user/invalidname
.
From Bill Dudney
I’d like to thank the many folks who have been to the Pragmatic iOS Studios
(
http://pragmaticstudio.com/ios
). Your questions, insights, and struggles have been
an inspiration for much of the material in this book. I always love walking
into a class early on the first day and feeling the energy of people excited to
learn something new. Listening to the questions and watching the victories
helped me immensely in understanding how to present iOS to developers new
to the platform.
Any mention of the Studios requires a heartfelt thanks to my co-teachers,
Daniel Steinberg and Matt Drance. I learn something new every time I deliver
the class with them.
My family put up with a distracted father and husband all too often
throughout the writing of this book. But I’d like to say a special thanks to my
wife, Sarah, for all her help in editing my first, second, and all-too-often third
drafts. I’d also like to thank a 2,000-year-old Jewish carpenter for touching
my life and making it so much more than it might have been.
Acknowledgments • x
report erratum • discuss
www.it-ebooks.info
[...]... to iOS 6 With all the advances in the tools and frameworks in iOS 6, it’s a great time to be starting our journey into iOS app development In fact, we should tell all our friends what we’re up to In this first chapter, that’s exactly what we’re going to do For our first example, we’re going to build an app to send out a tweet announcing that we’ve written our first iOS app We’ll get set up with the SDK. .. develop iOS 6 apps, we use Xcode 4 While “Xcode” generally refers to the integrated development environment (IDE) (in which we develop code and user interfaces and run a build process to generate the actual apps), it can also mean the entire collection of material we’ll need to build iOS applications When we download Xcode, we get not only the Xcode app itself but also the software development kits (SDKs)... SLServiceTypeTwitter]; [tweetVC setInitialText: @"I just finished the first project in iOS SDK Development #pragsios"]; [self presentViewController:tweetVC animated:YES completion:NULL]; } else { NSLog (@"Can't send tweet"); } 5 10 - } We’ve replaced our one-line C logging statement with several lines of ObjectiveC, which is what iOS uses for most of its high-level APIs, such as UIKit and the Social framework... and source code management We’re also adopting modern iOS development practices, such as using Objective-C properties exclusively instead of using traditional instance variables and getting private methods out of public header files Our goal is for this book to serve as a prerequisite for all the other iOS titles from the Pragmatic Bookshelf, such as iOS Recipes: Tips and Tricks for Awesome iPhone and... getting Xcode from the Mac App Store, and by the time we’re done we’ll be ready to upload our own apps to the iOS App Store Here’s a road map to the journey: • Chapter 1, Tweetings and Welcome to iOS 6, on page 1, starts by downloading and installing the SDK and beginning work on a first app, which uses iOS 6’s new Social framework to send a tweet telling the world that our journey is underway We’ll use Xcode’s... Technical Requirements The technical requirements for iOS development, in general terms, are pretty simple: a reasonably new Mac, running the most-recent production version of Mac OS X The specific version numbers increment ever upward; check out Xcode on the Mac App Store for the latest requirements For this edition, our baseline is Xcode 4.5 and the iOS 6 SDK (included with Xcode 4.5), running on Mountain... millions of units, and changed its name from iPhone OS to iOS to better reflect its multiple uses and perhaps to leave the door open to future devices The SDK has also grown in breadth and depth, adding new features, new frameworks, and new tools Since the first book, Apple has changed compilers and has radically overhauled Xcode, the primary iOS development environment As we did our day-to-day work with... platform—between Xcode 4, iOS 6, and the iPad—we decided that so much had changed that we would be better off starting off fresh This freed us to embrace everything that’s new, making a complete cut with the past and writing a truly up-to-date book And there’s so much that’s new! The radically overhauled Xcode 4 is the first version of the development tool that’s truly built for iOS development, rather www.it-ebooks.info... like the A5 comes a need for practical concurrent programming, something the iOS SDK answers with Grand Central Dispatch, a technology that allows programmers to divvy up small bits of code and data as “blocks” and let the system decide how best to run them In fact, it’s possible to have too much of a good thing, and the iOS 6 SDK is a good example In our first book, we worked to present most of the interesting... variable tweetVC, which gets the *character, because it, like all Objective-C objects, is a C pointer On lines 6–7, we set the initial text of the tweet to "I just finished the first project in iOS SDK Development #pragsios" by calling the setInitialText: method on tweetVC The leading @ identifies the string as an Objective-C NSString as opposed to a typical null-terminated C string This is all we need to . teach you the ins and
outs of Apple’s iOS SDK than Bill Dudney and Chris Adamson. Their all-new,
updated book, iOS SDK Development, is a must-read, plain. www.it-ebooks.info
www.it-ebooks.info
What readers are saying about
iOS SDK Development
Being a successful iOS developer means maintaining laser-like focus on the
Ngày đăng: 06/03/2014, 23:20
Xem thêm: iOS SDK Development docx, iOS SDK Development docx, A1. Wait! I Forgot (or Never Learned) C!