Book Image

Learning Swift Second Edition - Second Edition

By : Andrew J Wagner
Book Image

Learning Swift Second Edition - Second Edition

By: Andrew J Wagner

Overview of this book

Swift is Apple’s new programming language and the future of iOS and OS X app development. It is a high-performance language that feels like a modern scripting language. On the surface, Swift is easy to jump into, but it has complex underpinnings that are critical to becoming proficient at turning an idea into reality. This book is an approachable, step-by-step introduction into programming with Swift for everyone. It begins by giving you an overview of the key features through practical examples and progresses to more advanced topics that help differentiate the proficient developers from the mediocre ones. It covers important concepts such as Variables, Optionals, Closures, Generics, and Memory Management. Mixed in with those concepts, it also helps you learn the art of programming such as maintainability, useful design patterns, and resources to further your knowledge. This all culminates in writing a basic iOS app that will get you well on your way to turning your own app ideas into reality.
Table of Contents (19 chapters)
Learning Swift Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

This book will help you to get started with Swift in no time. It helps you understand the nuances of iOS programming not only from a conceptual but also from an implementation perspective. This book is an invaluable resource if you are looking forward to exploring the world of iOS application programming.

What this book covers

Chapter 1, Introducing Swift, will take the reader through the process of installing Swift and running their first Swift program, in order to expose its power right away.

Chapter 2, Building Blocks - Variables, Collections, and Flow Control, introduces you to the various built-in mechanisms Swift has for representing complex information in expressive and accessible ways, with the help of a real-world example.

Chapter 3, One Piece at a Time - Types, Scopes, and Projects, introduces the tools necessary to closely model the real world with code. It will teach you how to define your own custom types using structures, classes, and enumerations. It also explores the concept of scope and access control.

Chapter 4, To Be or Not To Be - Optionals, focuses on a special and critical type in Swift, called optionals. It includes a detailed explanation of how optionals work and how they can be used, which turns a seemingly complex topic into a very intuitive concept.

Chapter 5, A Modern Paradigm - Closures and Functional Programming, introduces you to a new way of thinking about code called functional programming. We learn how Swift supports this technique and how we can apply it to our programs to make it even more understandable and expressive.

Chapter 6, Make Swift Work For You - Protocols and Generics, describes what generics and protocols are and how they can provide power and safety at the same time.

Chapter 7, Everything Is Connected - Memory Management, dives deeper into the inner-workings of Swift. We discuss how a computer stores information and how we can use that knowledge in combination with some new tools in Swift, to ensure that our code remains responsive and minimizes its effect on battery life.

Chapter 8, Paths Less Traveled – Error Handling, goes into gracefully handling error situations in Swift with error throwing and catching.

Chapter 9, Writing Code the Swift Way - Design Patterns and Techniques, introduces the reader to the art of programming by taking them through a number of specific design patterns that help reduce the complexity of code.

Chapter 10, Harnessing the Past - Understanding and Translating Objective-C, develops a basic understanding of Objective-C with a focus on how it compares to Swift. This allows the reader to make use of the vast resources that exist in Objective-C to help with their Swift development.

Chapter 11, A Whole New World - Developing an App, focuses on explaining the process of creating a real world iOS application, with the help of an example.

Chapter 12, What's Next? - Resources, Advice, and the Next Steps, discusses how to move forward to become the best app developer you possibly can. It provides a list of resources and advice the reader can use to continue their Swift and app development learning process.

What you need for this book

To run the code in this book, you will need Xcode 7.2.

Who this book is for

If you want to build iOS or OS X apps using the most modern technology, this book is ideal for you. Learning Swift will place you into a small developer community that will explode in demand when all the development for Apple's platforms transitions to it. You will find this book especially useful if you are new to programming or if you have yet to develop for iOS or OS X.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

When mentioning pieces of code in text we will use the style as follows: "You can see that "Hello, playground" was indeed stored in the variable.

If the code is longer it will presented as a block as follows:

if invitees.count > 20 {
   println("Too many people invited")
}
else if invitees.count <= 3 {
    println("Not really a party")
}
else {
    println("Just right")
}

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Now, click on Connect on the Remote Desktop Viewer". Keyboard shortcuts will be displayed using the key style.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows

  • Zipeg/iZip/UnRarX for Mac

  • 7-Zip/PeaZip for Linux

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/LearningSwiftSecondEdition_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.