iOS 7 Programming Cookbook
Vandad Nahavandipoor
Beijing Cambridge Farnham Kln Sebastopol Tokyo
Special Upgrade Offer
If you purchased this ebook directly from oreilly.com, you have the following benefits:
- DRM-free ebooks use your ebooks across devices without restrictions or limitations
- Multiple formats use on your laptop, tablet, or phone
- Lifetime access, with free updates
- Dropbox syncing your files, anywhere
If you purchased this ebook from another retailer, you can upgrade your ebook to take advantage of all these benefits for just $4.99. to access your ebook upgrade.
Please note that upgrade offers are not available from sample content.
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 programmers 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. Thats 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 youd 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 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 Ive 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 youll 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.
Organization of This Book
In this book, we will discuss frameworks and classes that are available in the iOS 7 SDK. This book does its best to teach you the latest and the greatest APIs. As you know, some users of your apps may still be on older versions of iOS, so please consider those users and choose your APIs wisely, depending on the minimum iOS version that you want to target with your apps.
Apple has recommended that you write your apps so that they support and run on iOS 6 and iOS 7. This means you need to use the latest SDK as your base SDK (the SDK that you use to compile your app) and choose iOS 6 as your target, if thats what your business requirements dictate. If you are required to write your app to support only iOS 7, then you are in for a lot of fun, as you can use all the cool APIs that have been introduced in iOS 7 and discussed in this book.
Here is a concise breakdown of the material each chapter covers:
Explains how Objective-C classes are structured and how objects can be instantiated. 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.
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.
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.
Shows how you can work with table views to create professional-looking iOS applications . 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.
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.