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
Arrow up icon
GO TO TOP
Mastering Swift 5.3

You're reading from   Mastering Swift 5.3 Upgrade your knowledge and become an expert in the latest version of the Swift programming language

Arrow left icon
Product type Paperback
Published in Nov 2020
Publisher Packt
ISBN-13 9781800562158
Length 418 pages
Edition 6th Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jon Hoffman Jon Hoffman
Author Profile Icon Jon Hoffman
Jon Hoffman
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Taking the First Steps with Swift 2. Swift Documentation and Installing Swift FREE CHAPTER 3. Learning about Variables, Constants, Strings, and Operators 4. Optional Types 5. Using Swift Collections 6. Control Flow 7. Functions 8. Classes, Structures, and Protocols 9. Protocols and Protocol Extensions 10. Protocol-Oriented Design 11. Generics 12. Error Handling and Availability 13. Custom Subscripting 14. Working with Closures 15. Advanced and Custom Operators 16. Concurrency and Parallelism in Swift 17. Custom Value Types 18. Memory Management 19. Swift Formatting and Style Guide 20. Adopting Design Patterns in Swift 21. Other Books You May Enjoy
22. Index

What is Swift?

Swift is a programming language that was introduced by Apple at the Worldwide Developers Conference (WWDC) in 2014. Swift was arguably the most significant announcement at WWDC 2014 and very few people, including Apple insiders, were aware of the project's existence prior to it being announced.

It was amazing, even by Apple's standards, that they could keep Swift a secret for as long as they did and that no one suspected they were going to announce a new development language. At WWDC 2015, Apple made another big splash when they announced Swift 2. Swift 2 was a major enhancement to the Swift language. During that conference, Chris Lattner said that a lot of the enhancements were based on direct feedback that Apple received from the development community. It was also announced that Swift would become an open source project. In my opinion, this was the most exciting announcement of WWDC 2015.

In December 2015, Apple officially released Swift as open source with the https://swift.org/site, which is dedicated to the open source Swift community. The Swift repository is located on Apple's GitHub page (http://github.com/apple). The Swift evolution repository (https://github.com/apple/swift-evolution) tracks the evolution of Swift by documenting the proposed changes. A list of which proposals were accepted and rejected can be found in the evolution repository. In addition to these resources, Apple has moved away from using mailing lists as the primary form of communication with the Swift community, and has set up Swift forums (https://forums.swift.org).

Swift 3, which was released in 2016, was a major enhancement to the Swift language that was not source-compatible with previous releases of the Swift language. It contained fundamental changes to the language itself and to the Swift standard library. One of the main goals of Swift 3 was to be source-compatible across all platforms, so the code that was written for one platform would be compatible with all other platforms. This means that the code we develop for macOS should work on Linux.

In September 2017, Swift 4 was released. One of the primary goals of the Swift 4 compiler was to be source-compatible with Swift 3. This enables us to compile both Swift 3 and Swift 4 projects with the Swift 4 compiler. Apple has established a community-owned source-compatibility test suite that will be used to regression test changes to the compiler.

Projects that are added to the test suite will be periodically built against the latest development version of Swift to help us understand the impact of the changes being made to Swift. You can find the Swift source compatibility page here: https://swift.org/source-compatibility/.

One of the original goals of Swift 4 was to stabilize the Swift Application Binary Interface (ABI). The main benefit of a stable ABI is to allow us to distribute frameworks in a binary format across multiple versions of Swift. If a stable ABI is in place, we can build a framework with the Swift 4 compiler and have it work with applications that were written in future versions of Swift. This feature ended up being deferred to Swift 5.

With the release of Swift 5, the ABI has been declared stable for all Apple platforms. You can read Swift's ABI Stability Manifesto here: https://github.com/apple/swift/blob/master/docs/ABIStabilityManifesto.md. As development for Swift on other platforms, such as Linux, matures, the Swift Core team has said that they will evaluate stabilizing the ABI for those platforms as well. A stable ABI means that a library that is compiled for one version of Swift—let's say Swift 5—will theoretically work with future versions of Swift, without having to be recompiled.

Since Swift 5 was released, Apple has released three additional versions: 5.1, 5.2, and 5.3. Each of these releases has added to or improved Swift. Throughout this book, we will see some of these changes and show you how you can use them. However, one of the most exciting changes will not be shown because we do not have a way to actually show it. This change occurred in Swift 5.1 when the Swift community implemented the Language Server Protocol (LSP).

The LSP enables code editors and IDEs to standardize the support for languages. Before LSP, when an editor or IDE wanted to support a particular language, that support had to be built into the tool. With LSP, the language itself provides that functionality, so any editor or IDE that supports LSP can now support Swift with features such as syntax highlighting, autocomplete, and tooltips. This enables support for Swift in any editor that supports LSP, such as VSCode. This is pretty exciting news if you have ever tried to code a Swift application in vi.

One of the most exciting things, with the release of Swift 5.3, was the release of an officially supported Windows 10 port of Swift. This is exciting because we are now able to use our Swift knowledge to develop on the Windows platform. The Windows port is provided by Saleem Abdulrasool, platform champion for the Windows port of Swift.

The development of Swift was started in 2010 by Chris Lattner. He implemented much of the basic language structure when only a few people were aware of its existence. It wasn't until late 2011 that other developers began to contribute to Swift. In July 2013, it became a major focus of the Apple Developer Tools group.

Chris started working at Apple in the summer of 2005. He held several positions within the Developer Tools group and was the director and architect of that group when he left Apple in 2017. On his home page (http://www.nondot.org/sabre/), he notes that Xcode's playground (we'll talk more about playgrounds a little later in this chapter) became a personal passion of his because it makes programming more interactive and approachable. If you are using Swift on the Apple platform, you will be using playgrounds a lot as a test and experimentation platform. You can also use Swift Playgrounds on the iPad.

There are a lot of similarities between Swift and Objective-C. Swift adopts the readability of Objective-C's named parameters and dynamic object model. When we refer to Swift as having a dynamic object model, we are referring to the ability of types to change at runtime. This includes adding new (custom) types and changing/extending existing types.

While there are a lot of similarities between Swift and Objective-C, there are significant differences between them as well. Swift's syntax and formatting are a lot closer to Python than Objective-C, but Apple did keep the curly brackets. I know Python people would disagree with me, and that is all right because we all have different opinions, but I like the curly brackets. Swift actually requires the curly brackets for control statements, such as if and while, which eliminate bugs, such as goto fail in Apple's SSL library.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image