What’s New in Swift 5.3

Apple Just Announced Swift 5.3 Entered in the Release Phase, And It Will Bring Several Important Changes.

Ilario Salatino
May 17 · 6 min read

The Announcement

On the 25th of March Apple announced that the release process for Swift 5.3 has begun, it’s a major change since it will improve the overall language quality and performance, and will make Swift available for multiple platforms as Windows and Linux.
But let’s see in detail what’s new.

Enum Cases as Protocol Witnesses

Currently a class extending a protocol needs to match exactly the protocol’s requirements, for example if we write static requirements within a protocol:

Multiple Trailing Closures

Swift 5.3 finally introduced the possibility to use multiple trailing closures.

Some Background

First of all for those who don’t know what a trailing closure is, it’s a simple syntactic sugar that we can use when we have a closure parameter in a function:

The problem

This is an amazing feature and allows us to write cleaner and easier to read code, however it’s currently limited only to the last parameter of a function as we can see in the following example:

The Proposed Solution

With SE-0279 we will be allowed to insert extra trailing closures, just by adding extra labels, therefore the following code will compile.

A New Float16 Type

This is pretty straight forward, I’ll report the motivation explained by apple:

Multi-Pattern Catch Clauses

Currently swift allows only a single error type for each catch clause, that means that if we define the following enum

Add Collection Operations on Noncontiguous Elements

Currently we can use Range<Index> to refer to multiple consecutive positions in a Collection, but there’s not a simple way to do this for discontiguous positions, based on some condition.

Increase Availability of Implicit self in @escaping Closures when Reference Cycles are Unlikely to Occur

Currently in closures we need to use explicit self even in some cases where reference cycles are unlikely to happen, for example because we already captured self in the current closure:

Refine didSet Semantics

Currently, if we have a property with a “didSet” observer, the getter to get the oldValue is always called, even if observer doesn’t contain any reference to the oldValue in its body, for example the following code

Where Clauses on Contextually Generic Declarations

Currently a where clause on a member declaration can be used only by placing the member inside a specific extension, but this can sound confusing, let’s make an example.

Synthesized Comparable Conformance for Enum Types

Let’s say we want to define an Enum whose cases have an obvious semantic order, for example:

What’s wrong here?

In order to compare two Objects, they need to conform the Comparable protocol:

Package Manager Changes

With next Swift release there will be also several major improvements to Swift Package Manager.

Package Manager Resources

SE-0271 introduces support to resources as images and data files inside Swift Packages and makes them easily accessible, SE-0278 adds localization support for resources.

Package Manager Conditional Target Dependencies

SE-0273 adds the possibility for package authors to add specific dependencies differentiated by platform.

Package Manager Binary Dependencies

Swift Package Manager currently supports only source packages, SE-0272 adds support for Binary Packages as GoogleAnalytics and many more, and this will make the Swift Package Manager adoption move faster.

The Startup

Medium's largest active publication, followed by +643K people. Follow to join our community.

Ilario Salatino

Written by

iOS Developer from Italy based in Berlin https://www.linkedin.com/in/ilario-salatino-7b023b67/.

The Startup

Medium's largest active publication, followed by +643K people. Follow to join our community.

Ilario Salatino

Written by

iOS Developer from Italy based in Berlin https://www.linkedin.com/in/ilario-salatino-7b023b67/.

The Startup

Medium's largest active publication, followed by +643K people. Follow to join our community.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store