Preface

Welcome to Learning Swift! This book will help you put the Swift programming language into practice by walking you through the development of a complete application for iOS that features a wide array of features, including camera access, working with the filesystem, face detection, and the iOS graphics system. Along the way, we’ll also introduce you to new and advanced topics in the Swift programming language.

Swift is a pretty amazing modern language, taking the best from other newer languages without reinventing the wheel. Swift is easy to write, easy to read, and hard to make big mistakes in.

Our philosophy is that the best way to learn Swift is to build apps using it! To build apps, though, you need a great framework, and Apple has one of the best ones for building high-quality, featureful software: Cocoa Touch. This book could quite easily be titled Learning Cocoa Touch with Swift, or something similar, because the frameworks are just as important as the language itself. At the time of writing, Swift is currently at version 4, and has a bright future ahead of it.

Resources Used in This Book

We recommend following along with the book by writing code yourself as you progress through each chapter. If you get stuck, or just want to archive a copy of the code, you can find what you need via our website.

Audience and Approach

This book is solely focused on Swift 4 and does not cover the use of Objective-C. We might mention it occasionally, but we don’t expect you to know how to use it. We first cover the basics of the Swift 4 language, and then move on to teach as much of the language as we can, as well as the use of Cocoa Touch, through the construction of Selfiegram, a photo-taking app for iOS.

This book’s approach differs from that of other programming books that you may have encountered. As we’ve mentioned, we believe that the best way to learn Swift is to build something using it. We assume that you’re a reasonably capable programmer, but we don’t assume you’ve ever developed for iOS or used Swift or Objective-C before. We also assume that you’re fairly comfortable navigating macOS and iOS as a user.

Organization of This Book

In this book, we’ll be talking about Cocoa Touch, the framework used for developing iOS applications. Along the way, we’ll also be covering Swift, including its syntax and features.

In Part I, Welcome to Swift, we begin with a look at the tools used for programming with Swift, as well as the Apple Developer Program. Then we move on to the basics of the Swift programming language and structuring a program for Apple’s platforms, as well as common design patterns.

In Part II, Building Selfiegram, we start building Selfiegram, the iOS photo-taking application that’s the focus of the book. In this part, we’ll build the foundational features, like the ability to take photos and store them on disk.

In Part III, Polishing Selfiegram, we add a number of particularly interesting features, including a custom camera view, face detection, network access, and theming the app.

In Part IV, Beyond Developing Selfiegram, we discuss a number of features and tools that can help you in your further development work, including Xcode’s debugging and profiling tools, as well as third-party tools that can make your life easier.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Also used for commands and command-line output.

Tip

This element signifies a tip or suggestion.

Note

This element signifies a general note.

Caution

This element indicates a warning or caution.

Using Code Examples

Supplemental material (code examples, exercises, errata, etc.) is available for download at our website.

This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Learning Swift, 3rd Edition, by Jonathon Manning, Paris Buttfield-Addison, and Tim Nugent (O’Reilly). Copyright 2018 Secret Lab, 978-1-491-98757-5.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

O’Reilly Safari

Note

Safari (formerly Safari Books Online) is a membership-based training and reference platform for enterprise, government, educators, and individuals.

Members have access to thousands of books, training videos, Learning Paths, interactive tutorials, and curated playlists from over 250 publishers, including O’Reilly Media, Harvard Business Review, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Adobe, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and Course Technology, among others.

For more information, please visit http://oreilly.com/safari.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/learning-swift-3e.

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

Jon thanks his mother, father, and the rest of his crazily extended family for their tremendous support.

Paris thanks his mother, without whom he wouldn’t be doing anything nearly as interesting, let alone writing books.

Tim thanks his parents and family for putting up with his rather lackluster approach to life.

We’d all like to thank Rachel Roumeliotis, whose skill and advice were invaluable to completing the book. Likewise, all the O’Reilly Media staff we’ve interacted with over the course of writing the book have been the absolute gurus of their fields.

A huge thank you to Tony Gray and the Apple University Consortium (AUC) for the monumental boost they gave us and others listed on this page. We wouldn’t be writing this book if it weren’t for them. And now you’re writing books, too, Tony—sorry about that!

Thanks also to Neal Goldstein, who deserves full credit and/or blame for getting us into the whole book-writing racket.

We’re thankful for the support of the goons at MacLab (who know who they are and continue to stand watch for Admiral Dolphin’s inevitable apotheosis), as well as professor Christopher Lueg, Dr. Leonie Ellis, and the rest of the staff at the University of Tasmania for putting up with us. “Apologies” to Mark Pesce. He knows why.

Additional thanks to Mars G., Dave J., Rex S., Nic W., Andrew B., Jess L., and everyone else who inspires us and helps us. And very special thanks to Steve Jobs, without whom this book (and many others like it) would not have reason to exist.

Thanks also to our tech reviewers, with special thanks to Chris Devers and Nik Saers for their thoroughness and professionalism.

Finally, thank you very much for buying our book—we appreciate it! And if you have any feedback, please let us know. You can email us at lab@secretlab.com.au and find us on Twitter at @thesecretlab.

Get Learning Swift, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.