iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor - Own the ebook now and start reading instantly
iOS 7 Programming Cookbook 2nd Edition Vandad Nahavandipoor - Own the ebook now and start reading instantly
com
https://ebookname.com/product/ios-7-programming-
cookbook-2nd-edition-vandad-nahavandipoor/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookname.com/product/ios-4-programming-cookbook-
solutions-examples-for-iphone-ipad-and-ipod-touch-apps-1st-
edition-vandad-nahavandipoor/
https://ebookname.com/product/writing-game-center-apps-in-ios-
bringing-your-players-into-the-game-1st-edition-vandad-
nahavandipoor/
https://ebookname.com/product/ios-and-os-x-network-programming-
cookbook-1st-edition-jon-hoffman/
https://ebookname.com/product/handbook-of-ecological-and-
ecosystem-engineering-1st-edition-majeti-narasimha-vara-prasad/
Case Files Pediatrics Sixth Edition Eugene C. Toy
https://ebookname.com/product/case-files-pediatrics-sixth-
edition-eugene-c-toy/
https://ebookname.com/product/water-infrastructure-issues-1st-
edition-james-d-haffner/
https://ebookname.com/product/american-sign-language-the-easy-
way-2nd-edition-david-a-stewart/
https://ebookname.com/product/the-farther-adventures-of-robinson-
crusoe-the-stoke-newington-edition-daniel-defoe-editor/
https://ebookname.com/product/problem-solved-a-primer-for-design-
and-communication-first-edition-michael-johnson/
The hydrogen economy Opportunities and challenges
Michael Ball
https://ebookname.com/product/the-hydrogen-economy-opportunities-
and-challenges-michael-ball/
iOS 7 Programming Cookbook
Vandad Nahavandipoor
iOS 7 Programming Cookbook
by Vandad Nahavandipoor
Copyright © 2014 Vandad Nahavandipoor. 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 books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or [email protected].
Editors: Andy Oram and Rachel Roumeliotis Indexer: Angela Howard
Production Editor: Christopher Hearse Cover Designer: Randy Comer
Copyeditor: Zyg Group, LLC Interior Designer: David Futato
Proofreader: Julie Van Keuren Illustrator: Rebecca Demarest
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly
Media, Inc., iOS 7 Programming Cookbook, the image of a Cowan’s shrew tenrec, and related trade dress 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, Inc., was aware of a trade‐
mark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and author assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained
herein.
ISBN: 978-1-449-37242-2
[QG]
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
iii
1.27. Presenting Master-Detail Views with UISplitViewController 148
1.28. Enabling Paging with UIPageViewController 153
1.29. Displaying Popovers with UIPopoverController 158
iv | Table of Contents
5.9. Providing Contextual Menus on Collection View Cells 311
6. Storyboards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
6.1. Adding a Navigation Controller to a Storyboard 316
6.2. Passing Data from One Screen to Another 318
6.3. Adding a Tab Bar Controller to a Storyboard 325
6.4. Introducing Custom Segue Transitions to Your Storyboard 328
6.5. Placing Images and Other UI Components on Storyboards 332
7. Concurrency. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
7.1. Constructing Block Objects 342
7.2. Accessing Variables in Block Objects 346
7.3. Invoking Block Objects 352
7.4. Performing UI-Related Tasks with GCD 354
7.5. Executing Non-UI Related Tasks Synchronously with GCD 358
7.6. Executing Non-UI Related Tasks Asynchronously with GCD 361
7.7. Performing Tasks after a Delay with GCD 368
7.8. Performing a Task Only Once with GCD 371
7.9. Grouping Tasks Together with GCD 373
7.10. Constructing Your Own Dispatch Queues with GCD 377
7.11. Running Tasks Synchronously with Operations 380
7.12. Running Tasks Asynchronously with Operations 387
7.13. Creating Dependency Between Operations 393
7.14. Creating Timers 395
7.15. Creating Concurrency with Threads 400
7.16. Invoking Background Methods 406
7.17. Exiting Threads and Timers 407
8. Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
8.1. Enabling Security and Protection for Your Apps 418
8.2. Storing Values in the Keychain 422
8.3. Finding Values in the Keychain 424
8.4. Updating Existing Values in the Keychain 429
8.5. Deleting Exiting Values in the Keychain 432
8.6. Sharing Keychain Data Between Multiple Apps 434
8.7. Writing to and Reading Keychain Data from iCloud 440
8.8. Storing Files Securely in the App Sandbox 443
8.9. Securing Your User Interface 446
Table of Contents | v
9.3. Pinpointing the Location of a Device 453
9.4. Displaying Pins on a Map View 455
9.5. Displaying Pins with Different Colors on a Map View 459
9.6. Displaying Custom Pins on a Map View 465
9.7. Converting Meaningful Addresses to Longitude and Latitude 468
9.8. Converting Longitude and Latitude to a Meaningful Address 470
9.9. Searching on a Map View 472
9.10. Displaying Directions on the Map 475
vi | Table of Contents
13.1. Requesting Access to the Address Book 564
13.2. Retrieving a Reference to an Address Book 568
13.3. Retrieving All the People in the Address Book 571
13.4. Retrieving Properties of Address Book Entries 573
13.5. Inserting a Person Entry into the Address Book 577
13.6. Inserting a Group Entry into the Address Book 581
13.7. Adding Persons to Groups 584
13.8. Searching the Address Book 587
13.9. Retrieving and Setting a Person’s Address Book Image 592
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007
Table of Contents | ix
Preface
This edition of the book is not just an update, but a total remake of the previous edition.
iOS 7 changed everything: the look and feel, the way we use our iOS devices, and most
importantly, the way we program for iOS devices. This called for a substantial rewrite
indeed. I have added roughly 50 new recipes to this book, talking about things such as
UIKit dynamics, collection views, the keychain, push notifications, and whatnot. I have
also gone through all the example codes and figures and updated them for iOS 7.
iOS 7 is a huge step forward for this amazing operating system that we all, as program‐
mers and users, have grown to love and enjoy programming for. You must have noticed
how the focus of iOS 7 is on being dynamic: how your UI should adapt to various
movements and motions that can be applied to the device. What I mean by that is Apple
wants developers to really look at the details of their apps and bring real-world physics
and dynamics into them. That’s why Apple introduced UIKit Dynamics to the SDK, and
that is why this book has a whole chapter dedicated to this concept. The more expensive
a high-end device such as the new iPhone becomes, the more demanding the users will
get as well. Nobody blames them, though! They have just bought a fantastic and top-
of-the-line new iPhone or iPad and they want to see amazing apps running on them,
leveraging all the capabilities that those devices have to offer.
That is why now more than ever developers have to get an in-depth knowledge of the
SDK and what the SDK has to offer to the developers so that we can create better and
faster apps for iOS users. Apple introduced a lot of cool new APIs to the iOS 7 SDK, and
we are going to explore them in this book.
The focus of iOS 7 is dynamics!
Before you read about this book, maybe you’d like to know about my background a bit
and how I can help you through this journey. I will just briefly let you know who I am
and how I got to love iOS. I started out writing Basic code for my Commodore 64 when
I was a kid. I then moved on to buy my own PC and started experimenting with Assembly
code. At first, it was 8-bit Assembly for DOS. I then moved onto writing my own hobby
xi
operating system, which was never really released as a commercial product, for 32-bit
Intel x86 CPU architectures.
Among all the programming languages that I have programmed in, Assembly and
Objective-C are the two that have really been different from the others, and I’ve really
liked them. Assembly because of the purity of the language: a command does only one
thing and does that one thing well. I believe that I like Objective-C for the same reason,
and in fact iOS shares the same trait with Assembly and Objective-C. Even though iOS
is an operating system and not a programming language, whatever it does, it does it best
and better than its rivals. From its simplicity to the sheer power that you can harvest
from the software and the hardware combined, using technologies such as GCD, the
bar that iOS has set in terms of ease of use and beauty is unprecedented.
This edition of the book has seen all the recipes inside all chapters completely renewed
for iOS 7. All screenshots have been updated, and many more recipes—such as those
related to security and the keychain, UI dynamics, collection views, push and local
notifications, and many more—have exclusively been written for this edition of the
book. I really have had a fun time writing this edition of the book, and packed as it is
with new features, I hope you’ll enjoy reading it. May it be a valuable addition to your
tech-book library.
Audience
I assume you are comfortable with the iOS development environment and know how
to create an app for the iPhone or iPad. This book does not get novice programmers
started but presents useful ways to get things done for iOS programmers ranging from
novices to experts.
xii | Preface
Here is a concise breakdown of the material each chapter covers:
Chapter 1, Implementing Controllers and Views
Explains how Objective-C classes are structured and how objects can be instanti‐
ated. The chapter talks about properties and delegates and subscripting by keys and
indexes. Even if you are competent in Objective-C, I strongly suggest that you read
this chapter, even if you only skim through it, to understand the basic material that
is used in the rest of the book. In this chapter, we will also explore the common
usage of various UI components, such as alert views, segmented controls, switches,
and labels. We will also talk about customizing these components with the latest
APIs provided in the SDK.
Chapter 2, Creating Dynamic and Interactive User Interfaces
Talks about UIKit Dynamics, the newest addition to the UIKit framework. These
dynamics allow you to add real-life physics and dynamics to your UI components.
This will allow you to create even livelier user interfaces with very small effort on
your side.
Chapter 3, Auto Layout and the Visual Format Language
Explains how you can take advantage of Auto Layout in the iOS SDK in order to
construct your UI in such a way that it can be resized and stretched to pretty much
any screen dimension.
Chapter 4, Constructing and Using Table Views
Shows how you can work with table views to create professional-looking iOS ap‐
plications. Table views are very dynamic in nature, and as a result, programmers
sometimes have difficulty understanding how they should work with them. By
reading this chapter and trying out the example code, you will gain the knowledge
that is required to comfortably work with table views.
Chapter 5, Building Complex Layouts with Collection Views
Collection views have been available to OS X programmers for quite some time
now, and Apple decided to provide the same APIs to iOS programmers in the iOS
SDK. Collection views are very much like table views, but they are much more
configurable and dynamic. Where in table views we have the concept of sections
and rows in each section, collection views bring columns to the equation as well,
so that you can display many items in one row if you want to. In this chapter we
will have a look at all the great user interfaces that you can create using collection
views.
Chapter 6, Storyboards
Demonstrates the process of storyboarding, the new way to define the connections
between different screens in your app. The great thing about storyboarding is that
you don’t have to know anything about iOS programming to get a simple app run‐
ning. This helps product analysts, product owners, or designers who work inde‐
pendently of developers to gain knowledge of the UI components iOS offers and to
Preface | xiii
Other documents randomly have
different content
enixa fuerat, et eam regi Apuliae Pilunno praesentaverunt,
qui eam uxorem duxit. Hujus rei gratia antiqui in littore illo
Danae templum aedificaverunt. Item secus hunc
Metapontum dicunt Palladis templum fuisse, in quo diu
servata sunt Epii instrumenta, quibus durum equum apud
Ilium fabricaverat, et bipennes aereae et arma Diomedis
sociorum deposita et diu ostensa sunt. Dicunt insuper, ibi
canes fuisse Graecis venientibus laeta garrulitate
blandientes; sed quod longe majus et verius et venerabilius
est, hoc in monte anno Domini 481 tempore Senonis
Michaelis archangeli specus incolis ostensus est mirabili
prodigio, ubi summa devotione a Christianis visitatur. In hoc
monte dicit Catholicon, ibi ferula crescit herba, quae dicitur
ferula, quia tam calidae naturae est, quod austro flante
incenditur herba, et quandoque tota regio aduritur. Ibi in
mari sunt insillae, quae dicuntur insulae Diomedis, ubi
occiso ab Illyricis templum ingens aedificatum fuit. Hic
Diomedes dux audacissimus cum caeteris Graecis ad
obsidionem Trojanam accessit et cum Hectore et Aenea
congressiones fecit ipsumque Martem vulneravit et
Venerem, Aeneam protegere volentem, qui cum in
Graeciam repatriare vellet et uxorem suam cum alio
concubuisse audiret, patriam renuit et in exilium se
relegavit navigans in Apuliam, et oppugnato monte Gargano
et aedificata Siponto interfectus ab Aenea fuit et deificatus,
cujus socii in aves conversi ejus templum circumvolare
dicuntur. Sunt enim aves albae, quas Latini diomedes,
Graeci herodios vocant, quae nusquam reperiuntur, nisi in
insula Diomedis, et omnibus infestae sunt et clamant,
demtis Graecis, et vulgus credidit, fuisse socios Diomedis,
et singulis diebus aquam rostris sumunt et templum
Diomedis perfundunt. De his loquitur Augustinus de civitate
Dei et in Spec. Natur. L. 17. C. 68.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com