Mastering Swift 5
Fifth Edition
Deep dive into the latest edition of the Swift programming language
Jon Hoffman
BIRMINGHAM - MUMBAI
Mastering Swift 5Fifth Edition
Copyright 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Kunal Chaudhari
Acquisition Editor: Larissa Pinto
Content Development Editor: Arun Nadar
Technical Editor: Jinesh Topiwala
Copy Editor: Safis Editing
Project Coordinator: Kinjal Bari
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Graphics: Alishon Mendonsa
Production Coordinator: Nilesh Mohite
First published: June 2015
Second edition: November 2015
Third Edition: October 2016
Forth Edition: September 2017
Fifth Edition: April 2019
Production reference: 1300419
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78913-986-0
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Packt.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.
At www.packt.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the author
Jon Hoffman has over 20 years' experience in the field of information technology. Over those 20 years, Jon has worked in the system administration, network administration, network security, application development, and architecture arenas. Currently, Jon works as an Enterprise Software Manager at Syntech Systems. Jon has developed extensively for the iOS platform since 2008. This includes several apps that he has published in the App Store, apps that he has written for third parties, and numerous enterprise applications. Some of Jon's other interests are watching Baseball (Go Sox) and Basketball (Go Celtics). Jon also really enjoys Tae Kwon Do, where he and his oldest daughter earned their black belts together early in 2014.
With this being the fifth edition of the Mastering Swift book, I would like to thank everyone who has given me encouragement, positive feedback, and constructive criticism through the years. That includes my family, friends, co-workers, and everyone at Packt.
About the reviewers
Gene De Lisa has been a software developer since the early 1980s in a wide variety of languages and platforms, He has been programming in iOS since 2009, and Swift since its release day in June 2014. He earned his doctorate in 1993. He has been an independent consultant in Enterprise Java since the 1990s and iOS since 2012.
Vinod Madigeri is a senior software engineer with expertise in full-stack app development. He received his Masters in Computer Science from the University of Utah in 2015. He has worked in several industries (telecommunication, game technologies, and consumer electronics) as a developer, team leader, and mentor writing software in C, C++, Python, Objective-C, and Swift for macOS and iOS platforms.
Currently, he spends much of his time exploring Machine Learning as a skill to complement his software development efforts.
Vinod has also been a technical reviewer for ObjectOriented Programming with Swift, Hands-On Full-Stack Development with Swift, and Multiplayer Game Development with HTML5.
I'd like to thank my wife, Shruti, for her constant support, encouragement, and vanguard thoughts.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Preface
Swift is a general-purpose programming language that takes a modern approach to development. It was first introduced by Apple at the Worldwide Developers Conference (WWDC) in 2014. Five years later, they released version 5 of Swift.
Swift 5 offers many enhancements and improvements to the Swift language with the biggest being ABI stability. Some of the other improvements are the ability to create raw strings, handling of future enum cases, and added isMultiple(of:) to integers just to name a few.
Who this book is for
This book is for the developer who wants to dive into the newest version of Swift. If you are a developer that learns best by looking at, and working with code, then this book is for you. A basic understanding of Apples tools is beneficial but not mandatory.
What this book covers
, Taking the First Steps with Swift, will introduce you to the Swift programming language and discuss what inspired Apple to create Swift. We'll also go over the basic syntax of Swift and how to use Playgrounds to experiment and test Swift code.
, Learning about Variables, Constants, Strings and Operators will introduce you to variables and constants in Swift and when to use them. There will be brief overviews of the most common variable types with examples on how to use them. This chapter concludes by showing examples of how to use the most common operators in the Swift language.
Next page