Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mastering Swift 5.3
Mastering Swift 5.3

Mastering Swift 5.3: Upgrade your knowledge and become an expert in the latest version of the Swift programming language , Sixth Edition

eBook
AU$29.99 AU$42.99
Paperback
AU$53.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Swift 5.3

Swift Documentation and Installing Swift

I spent a lot of my career working as a Linux System Administrator and Network Security Administrator. These positions required me to compile and install packages from source. There are a lot of advantages to building packages from source rather than downloading prebuilt binaries. The biggest advantage, in my opinion, is that you can get the latest version without having to wait for someone else to build it. This allows me to patch my systems with the latest security updates without delay. With Swift, we are also able to download the latest code and compile ourselves without having to wait for someone else to build it.

In this chapter, you will learn:

  • About the swift.org website and what it offers
  • How to find the latest documentation on Swift
  • Ways to install Swift
  • How to build Swift from source with its full toolchain and package manager

In the previous chapter, we mentioned that Apple has released...

Swift.org

On December 3, 2015, Apple officially released the Swift language, supporting libraries, the debugger, and the package manager to the open source community under the Apache 2.0 license. At that time, the swift.org site was created as the community's gateway to the project. This site has a wealth of information and should be your primary site to find out what is happening in the Swift community and the language itself. The blog posts will keep you up to date with new releases of Swift, new Swift open source libraries, changes to the standard library, and other Swift news.

You can also download pre-built binaries for several flavors of Linux. At the time this book is being written, we can download pre-built binaries for Ubuntu 16.04, Ubuntu 18.04, Ubuntu 20.04, CentOS 8, and Amazon Linux 2. The getting started page provides a list of dependencies for the previously mentioned flavors of Linux and instructions on how to install the binaries.

The website...

Swift documentation

Apple and the Swift community, as a whole, have released a number of resources to help developers program in Swift. Apple's official documentation, which can be found at https://developer.apple.com/documentation/, includes API documentation for Swift as well as all of Apple's frameworks. Only a small portion of Apple's frameworks are open source and work across all platforms; however if you are looking to get started on one of Apple's frameworks this is definitely the place to start. However it can be hard to find documentation on specific Swift APIs.

To quickly find documentation on Swift's API, my favorite site is https://swiftdoc.org. This site is incredibly easy to navigate and has autogenerated documentation for all types, protocols, operators, and global functions that make up the Swift language. I have noticed that this site does not always stay up to date; however, it is a great reference for any Swift developer. The code that...

Installing Swift from swift.org

If you are developing on and for the Apple platform, I strongly suggest that you stick with the version of Swift that comes with Xcode. Apple will not approve an app that was compiled using a version of Swift that is different than the one that came with the version of Xcode that you are using. This may seem a little extreme, but it ensures that the apps are compiled with a stable version of Swift and one that has been fully vetted to work with your version of Xcode.

If you are using one of the flavors of Linux that has pre-built binaries on the swift.org site, it is recommended that you use those. They are the easiest and quickest path to getting Swift up and running. You can also find complete installation instructions with a list of dependencies on the swift.org site under the Getting Started section.

If pre-built binaries are not provided for your flavor of Linux, if you want to try the latest version of Swift, or if you just want...

Building Swift and the Swift toolchain from source

There are a number of sites that show you how to build Swift from source, but unfortunately most of these sites give directions for building just the Swift language itself without the toolchain. I find that not very useful, unless you are only writing very simple applications. In my opinion, building Swift for Linux without the entire toolchain and the package manager is more of an exercise of "Can I do it" rather than building something you can use long term.

While using the latest build of Swift is not recommended for production systems, it does enable us to use the latest features of the language and also verify that changes introduced in our application are compatible with future versions of the Swift language.

In this chapter, we will look at how we can build Swift, its entire toolchain, and the Swift package manager from source. Since each flavor of Linux and macOS are somewhat different, I need...

Using the Swift package manager

There is a lot that you can do with the package manager that makes it a necessity for creating complex applications on the Linux platform. It helps with adding dependencies to projects and enables us to break our code up into multiple files and create library projects. You can use the package manager on the Mac platform as well, but I do find it easier to use Xcode.

For the examples in this book, we will not need to add dependencies or use multiple files. Let's see how we can simply build and run an executable project in the package manager so you can use it to run the examples from this book if you would like. Keep in mind you are able to use the package manager on the Apple platform as well. When the package manager created main.swift in the Sources/test/ directory it added the following code to it:

print("Hello, world!")

This code gives us the basic Hello World application. You can replace this code with examples from...

Using the Swift compiler

The Swift compiler is the basic utility to build Swift code and it is used by the package manager, Xcode, and any other utility that builds Swift code into executables. We can also call it ourselves. To see how to call it ourselves, create a file named hello.swift and add the print("Hello, world!") code to it as shown with the following code:

echo `print("Hello, world!")` >> hello.swift

Now we can compile this code with the following command, which calls the Swift compiler:

swiftc hello.swift

Finally we can execute the newly created application like we would any other executable:

./hello

And we will be greeted with our Hello, world! message.

Summary

In this chapter, we looked at some of the different documentation that Apple and the Swift community offer. This documentation can be essential as you are learning Swift and also for reference once you have mastered the language itself. We also looked at how we can build and install Swift and its full toolchain. While using the latest build of Swift is not recommended for production systems, I usually keep a virtual machine or my desktop setup with a recent build. This enables me to use the latest features of the language and also run my code against it to make sure I am not introducing changes that are not compatible with future versions of the language.

In the next chapter, we will start to get into the language itself and we will see how to use variables and constants in Swift. We will also look at the various data types and how to use operators in Swift.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Sixth edition of this bestselling book, improved and updated to cover the latest version of the Swift 5.3 programming language
  • Get to grips with popular and modern design techniques to write easy-to-manage Swift code
  • Use core Swift features such as concurrency, generics, and copy-on-write in your code

Description

Over the years, Mastering Swift has proven itself among developers as a popular choice for an in-depth and practical guide to the Swift programming language. This sixth edition comes with the latest features, an overall revision to align with Swift 5.3, and two new chapters on building swift from source and advanced operators. From the basics of the language to popular features such as concurrency, generics, and memory management, this in-depth guide will help you develop your expertise and mastery of the language. As you progress, you will gain practical insights into some of the most sophisticated elements in Swift development, including protocol extensions, error handling, and closures. The book will also show you how to use and apply them in your own projects. In later chapters, you will understand how to use the power of protocol-oriented programming to write flexible and easier-to-manage code in Swift. Finally, you will learn how to add the copy-on-write feature to your custom value types, along with understanding how to avoid memory management issues caused by strong reference cycles. By the end of this Swift book, you will have mastered the Swift 5.3 language and developed the skills you need to effectively use its features to build robust applications.

Who is this book for?

This book is for beginners with a basic understanding of programming and experienced developers looking to learn Swift programming. Familiarity with Apple's tools will be beneficial but not mandatory. All examples should also work on the Linux and Windows platforms

What you will learn

  • Understand core Swift components, such as operators, collections, control flows, and functions
  • Identify how and when to use classes, structures, and enumerations
  • Use protocol-oriented design with extensions to write easy-to-manage code
  • Leverage design patterns with Swift to solve commonly occurring design problems
  • Apply copy-on-write for your custom value types to improve performance
  • Add concurrency to your applications using Grand Central Dispatch and operation queues
  • Implement generics to write flexible and reusable code

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 23, 2020
Length: 418 pages
Edition : 6th
Language : English
ISBN-13 : 9781800569973
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 23, 2020
Length: 418 pages
Edition : 6th
Language : English
ISBN-13 : 9781800569973
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
AU$249.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 183.97
iOS 14 Programming for Beginners
AU$75.99
SwiftUI Projects
AU$53.99
Mastering Swift 5.3
AU$53.99
Total AU$ 183.97 Stars icon
Banner background image

Table of Contents

22 Chapters
Taking the First Steps with Swift Chevron down icon Chevron up icon
Swift Documentation and Installing Swift Chevron down icon Chevron up icon
Learning about Variables, Constants, Strings, and Operators Chevron down icon Chevron up icon
Optional Types Chevron down icon Chevron up icon
Using Swift Collections Chevron down icon Chevron up icon
Control Flow Chevron down icon Chevron up icon
Functions Chevron down icon Chevron up icon
Classes, Structures, and Protocols Chevron down icon Chevron up icon
Protocols and Protocol Extensions Chevron down icon Chevron up icon
Protocol-Oriented Design Chevron down icon Chevron up icon
Generics Chevron down icon Chevron up icon
Error Handling and Availability Chevron down icon Chevron up icon
Custom Subscripting Chevron down icon Chevron up icon
Working with Closures Chevron down icon Chevron up icon
Advanced and Custom Operators Chevron down icon Chevron up icon
Concurrency and Parallelism in Swift Chevron down icon Chevron up icon
Custom Value Types Chevron down icon Chevron up icon
Memory Management Chevron down icon Chevron up icon
Swift Formatting and Style Guide Chevron down icon Chevron up icon
Adopting Design Patterns in Swift Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.7
(15 Ratings)
5 star 33.3%
4 star 33.3%
3 star 13.3%
2 star 13.3%
1 star 6.7%
Filter icon Filter
Top Reviews

Filter reviews by




Nicholas Jan 15, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I purchased the previous version of this book with a humble bundle a while back so this review will take a moment to focus on whats new in the 6th ed:A chapter about Swift documentation / installing swift was inserted and is now chapter 2. This will help you understand how to work with swift on Linux if you dont have a Mac, HOWEVER sticking to XCode on Mac is the optimal experience.Also new in this verson: error handling gets an added section on multi pattern catch clauses which is new to swift 5.3 and a good addition by the author.Synthesized Comparable conformance for enumerations is new to 5.3 and is also briefly covered in this book.A new chapter on Custom Operators is in this edition. I feel like this chapter is geared toward really experienced developers because it was a bit advanced for where I am in my journey.On the book itself. You dont really need much if any pre-existing knowledge on the topic before you start with this. The book has a chapter on almost every topic ranging from variables, collection types, control flow, to functions and more. The book takes time to explain differences between swift and other languages (such as semi-colons or assignment operators) so that is helpful if you are coming from that background. Towards the end he provides a style/formatting guide which will help you keep your code looking professional when its reviewed by potential employers. The design patterns chapter is cool but every employer has their own design pattern so dont waste your time memorizing these, a general understanding is more than enough.As a final note I would like to say this book is really good at teaching you the concepts of Swift as it stands in 5.3, with example code in the book done in playgrounds. After this book I suggest following along with app building tutorials on youtube to help you build your practical skillset and show you how to apply the really great concepts you get from this book. It can be a little dry reading at times but its straight to the point and I highly recommend reading this if youre trying to really get a grip on the language.
Amazon Verified review Amazon
Jay Jay Jan 11, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Thanks
Amazon Verified review Amazon
Andre P. Dec 09, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
"Mastering Swift" has been my to go resource for Swift from its First Edition. The brand new Sixth Edition contains all the relevant updates for Swift 5.3, which allows iOS developers to easily keep up with the language evolution. My favorite chapters are "Concurrency and Parallelism in Swift", which focuses on GCD, and "Adopting Design Patterns in Swift".Definitely a great addition to any programming books collection!
Amazon Verified review Amazon
Richard Albury Dec 13, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a pleasant surprise. I breezed through the book in a week, and despite a few years of Objective-C and Swift experience, I still learned a few things.It does a great job of hitting the important aspects of the language while also providing good context, so it’s not just a collection of dry pedagogical exercises. The chapter on swift.org and building Swift is a great introduction to one of Swift’s hidden strengths: an enthusiastic and diverse community of people who care about this open, developer-driven language and the platforms it runs on.I also have to call out the chapter on closures: it’s one of the better introductions to a topic a lot of beginning Swift developers struggle with. The chapter on concurrency deserves mention as well: these two topics are fundamental to master, and the book does an exceptional job with them.Finally, the ending chapter on design patterns provides a good grounding in an advanced topic.Highly recommended. If you had to buy a single book on Swift, this would be it.
Amazon Verified review Amazon
Just Me Dec 07, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have purchased a copy of almost all of the Mastering Swift books because I find them incredibly informative. The author does a great job of teaching Swift while also covering the most important new features of the language. While the first few chapters are geared towards someone first learning the language, the later chapters are a must read for anyone that wants to master the Swift Language. From Protocol Oriented Programming techniques and Copy-on-Write to Concurrency and Generics, this book covers almost all of the advanced topicsWhen I first received my copy of this book, I went right to the Advanced Operators chapters which is one of the two new chapters added in this revision. This is one of the few books that cover details like the Bitwise operators and custom operators. This chapter is a great addition to the book.Just like previous revisions of this book, I consider this a most read for beginners to the Swift Language and also for experience developers that want to take their knowledge to the next level.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.