Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Swift 5.3 - Sixth Edition
Mastering Swift 5.3 - Sixth Edition

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

By Jon Hoffman
$26.99 $17.99
Book Nov 2020 418 pages 6th Edition
eBook
$26.99 $17.99
Print
$38.99
Subscription
$15.99 Monthly
eBook
$26.99 $17.99
Print
$38.99
Subscription
$15.99 Monthly

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
Buy Now

Product Details


Publication date : Nov 23, 2020
Length 418 pages
Edition : 6th Edition
Language : English
ISBN-13 : 9781800562158
Category :
Languages :
Table of content icon View table of contents Preview book icon Preview Book

Mastering Swift 5.3 - Sixth Edition

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.

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

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
Buy Now

Product Details


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

Table of Contents

23 Chapters
Preface Chevron down icon Chevron up icon
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

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
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.