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 note-taking application for the Apple iOS, OS X, and watchOS platforms.

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 really hard to make 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 several: Cocoa, Cocoa Touch, and WatchKit, to name only a few. This book could quite easily be titled Learning Cocoa and 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 2.2, and has a bright future ahead of it.

Organization of This Book

In this book, we’ll be talking about Cocoa and Cocoa Touch, the frameworks used on OS X and iOS, respectively. Along the way, we’ll also be covering Swift, including its syntax and features.

In Part I, Swift Basics, 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.

Chapter 1 covers the basics of Apple’s developer program, and guides you through a simple Swift app.

Chapter 2 explores all the basics of Swift, and prepares you for using it to build more complex applications.

Chapter 3 discusses Swift’s object-oriented features, as well as the structure of a good app.

In Part II, An OS X App, we build a simple note-taking application for Macs, targeting OS X. Along the way, we discuss the design of the app, how it’s structured, how it uses documents, and how to build all the features.

Chapter 4 starts off our OS X notes app, and sets up the document model, and icon.

Chapter 5 goes into detail on working with documents in OS X apps.

Chapter 6 connects the app to iCloud, and finishes up the OS X app.

In Part III, An iOS App, we build a fully featured iOS note-taking application as a companion for the OS X app from Part II.

Chapter 7 starts off our iOS app, and sets up the same document model for iOS.

Chapter 8 connects the iOS app to iCloud.

Chapter 9 creates an interface on iOS for displaying our notes.

Chapter 10 sets up the iOS app to handle attachments.

Chapter 11 adds image support to the iOS app.

Chapter 12 adds sharing and searching support to the iOS app.

Chapter 13 adds a today widget to the iOS app.

Chapter 14 adds location, audio, video, and contact attachments to the iOS app, as well as notifications.

Chapter 15 finishes the iOS app with a whole lot of polish!

In Part IV, Extending Your Apps, we add a watchOS app, and explore bug hunting and performance tuning.

Chapter 16 adds a watchOS app to the iOS app, allowing for Apple Watch support.

Chapter 17 explores debugging and performance tuning.

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.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Tip

This element signifies a tip or suggestion.

Note

This element signifies a general note.

Caution

This element indicates a warning or caution.

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of plans and pricing for enterprise, government, education, and individuals.

Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, 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, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online.

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.

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 our editors, Rachel Roumeliotis and Brian MacDonald—their 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 Rex S., Nic W., Andrew B., Jess L., and Ash J., for a wide variety of reasons. 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 Tony Gray 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 @thesecretlab.