Introducing Swift 5.3
Introduced by Apple during 2020, the main goal in Swift 5.3 is to enhance quality and performance and to expand the number of platforms on which Swift is available by adding support for Windows and additional Linux distributions.
Now, let's review some of the new language features.
Multi-pattern catch clauses
With this new feature, Swift will allow multiple error-handling blocks inside a do catch
clause. Take a look at the following example.
Imagine that we have a performTask()
function that can throw different types of TaskError
errors:
enum TaskError: Error { case someRecoverableError case someFailure(msg: String) case anotherFailure(msg: String) } func performTask() throws -> String { throw TaskError.someFailure(msg: "Some Error") } func recover() {}
Prior to Swift 5.3, if we want to handle different TaskError
cases inside a do catch
block, we need to add a switch
statement...