iOS Programming: The Big Nerd Ranch Guide
by Christian Keur and Aaron Hillegass
Copyright 2020 Big Nerd Ranch
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, contact
Big Nerd Ranch
200 Arizona Ave NE, Suite 200
Atlanta, GA 30307
(770) 817-6373
https://www.bignerdranch.com
book-comments@bignerdranch.com
The 10-gallon hat is a trademark of Big Nerd Ranch.
Exclusive worldwide distribution of the English edition of this book by
Pearson Technology Group
800 East 96th Street
Indianapolis, IN 46240 USA
http://www.informit.com
The authors and publisher have taken care in writing and printing this book but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
App Store, Apple, Cocoa, Cocoa Touch, Finder, Instruments, iCloud, iPad, iPhone, iPod, iPod touch, iTunes, Keychain, Mac, macOS, Multi-Touch, Objective-C, Quartz, Retina, Safari, and Xcode are trademarks of Apple, Inc., registered in the U.S. and other countries.
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 publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
ISBN-10 013526555X
ISBN-13 978-0135265550
Seventh edition, first printing, March 2020
Release E.7.1.1
Acknowledgments
While our names appear on the cover, many people helped make this book a reality. We would like to take this chance to thank them.
First and foremost we would like to thank Joe Conway for his work on the early editions of this book. He authored the first three editions and contributed greatly to the fourth edition as well. Many of the words in this book are still his, and for that, we are very grateful.
A couple other people went above and beyond with their help on this book. They are Amit Bijlani, Chris Downie, Chris Morris, Jacob Bullock, Juan Pablo Claude, Mikey Ward, and Zachary Waldowski.
The other instructors who teach the iOS Bootcamp feed us a never-ending stream of suggestions and corrections. Over the years, they have included Ben Scheirman, Bolot Kerimbaev, Brian Hardy, Chris Downie, Chris Morris, Drew Kreuzman, Gabe Hoffman, JJ Manton, Jacob Bullock, John Gallagher, Jonathan Blocksom, Joseph Dixon, Juan Pablo Claude, Mark Dalrymple, Matt Bezark, Matt Mathias, Mike Zornek, Mikey Ward, Pouria Almassi, Robert Edwards, Rod Strougo, Scott Ritchie, Step Christopher, Thomas Ward, TJ Usiyan, Tom Harrington, and Zachary Waldowski. These instructors were often aided by their students in finding book errata, so many thanks are due to all the students who attend the iOS Bootcamp.
Thanks to all the employees at Big Nerd Ranch who helped review the book, provided suggestions, and found errata.
Our tireless editor, Elizabeth Holaday, took our distracted mumblings and made them into readable prose.
Simone Payment jumped in to provide proofing.
Ellie Volckhausen designed the cover. (The photo is of the bottom bracket of a bicycle frame.)
Chris Loper at IntelligentEnglish.com designed and produced the print and ebook versions of the book.
The amazing team at Pearson Technology Group that has patiently guided us through the business end of book publishing.
The final and most important thanks goes to our students, whose questions inspired us to write this book and whose frustrations inspired us to make it clear and comprehensible.
Introduction
As an aspiring iOS developer, you face three major tasks:
You must learn the Swift language. Swift is the recommended development language for iOS. The first two chapters of this book are designed to give you a working knowledge of Swift.
You must master the big ideas. These include things like delegation, archiving, and the proper use of view controllers. The big ideas take a few days to understand. When you reach the halfway point of this book, you will understand these big ideas.
You must master the frameworks. The eventual goal is to know how to use every method of every class in every framework in iOS. This is a project for a lifetime: There are hundreds of classes and thousands of methods available in iOS, and Apple adds more classes and methods with every release of iOS. In this book, you will be introduced to each of the subsystems that make up the iOS SDK, but you will not study each one deeply. Instead, our goal is to get you to the point where you can search and understand Apples reference documentation.
We have used this material many times at our iOS bootcamps at Big Nerd Ranch. It is well tested and has helped thousands of people become iOS developers. We sincerely hope that it proves useful to you.
Prerequisites
This book assumes that you are already motivated to learn to write iOS apps. We will not spend any time convincing you that the iPhone, iPad, and iPod touch are compelling pieces of technology.
We also assume that you have some experience programming and know something about object-oriented programming. If this is not true, you should probably start with Swift Programming: The Big Nerd Ranch Guide.
What Has Changed in the Seventh Edition?
All the code in this book has been updated for Swift 5.2. Throughout the book, you will see how to use Swifts capabilities and features to write better iOS applications. We have come to love Swift at Big Nerd Ranch and believe you will, too.
Other additions include new chapters on container view controllers and custom controls and a revamped chapter on animations. We have also updated various chapters to use the technologies and APIs introduced in iOS 11, 12, and 13.
This edition assumes that the reader is using Xcode 11.4 or later and running applications on an iOS 12 or later device.
Besides these obvious changes, we made thousands of tiny improvements that were inspired by questions from our readers and our students. Every chapter of this book is just a little better than the corresponding chapter from the sixth edition.
Our Teaching Philosophy
This book will teach you the essential concepts of iOS programming. At the same time, you will type in a lot of code and build a bunch of applications. By the end of the book, you will have knowledge experience. However, all the knowledge should not (and, in this book, will not) come first. That is the traditional way of learning we have all come to know and hate. Instead, we take a learn-while-doing approach. Development concepts and actual coding go together.
Here is what we have learned over the years of teaching iOS programming: