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 permissions@oreilly.com.
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 bookquestions@oreilly.com.
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.