Swift 6 New Features

Md. Ibrahim Hassan
Swiftify
Published in
5 min readMar 18, 2024

--

Apple is planning to release Swift 6 in September 2024, alongside Xcode 16. This will be the first major Swift update in five years since Swift 5. This release will be on the 10th anniversary of Swift. Over the years, Swift has evolved significantly, from a mere improvement over Objective-C to a safe, multi-paradigm, and performant language that is easy to use.

Apple had previously mentioned that there would be a succession of
Swift 5.x versions introducing incremental changes and new features to pave the way for Swift 6. The major goals mentioned were to improve concurrency support and the memory ownership model. At this point, these have been achieved to a great extent.

Let’s quickly recap the evolution of Swift 5.x versions over the years.

Swift 5.1 (Sept 2019) added opaque return types (foundation feature for SwiftUI) implicit returns, and module format stability.

Swift 5.2 (Mar 2020) brought features like key path expressions as functions, and improved diagnostics.

Swift 5.3 (Sept 2020) brought various language improvements, such as multi-pattern errors catching, multiple trailing closures (which led to significant improvements to SwiftUI APIs), and Swift Package Manager improvements.

Swift 5.4 (Apr 2021) added support for multiple variadic parameters in functions, and result builder.

Swift 5.5 (Sept 2021) was a massive update, bringing concurrency-focused features like async/await, async sequences, structured concurrency, actors, global actors, and Sendable protocol/closures. It also enables the long-awaited interchangeable use of CGFloat and Double types. This update laid the groundwork for other concurrency-related updates in subsequent versions.

Swift 5.6 (Mar 2022) further improved concurrency and language refinements like type placeholders and existential Any. It also added plugins for Swift Package Manager.

Swift 5.7 (Sept 2022) introduced shorthand syntax for unwrapping optionals, Swift Regex, improved interoperability with C APIs, concurrency improvements, and also features a smaller and faster standard library.

Swift 5.8 (Mar 2023) relaxed limitations on variables in result builders, improved implicit self, and allowed back deployment of functions.

Swift 5.9 (Sept 2023) enhanced generics with value and type parameter packs (which eliminated the 10 view limit in SwiftUI), added macros, improved control flow with if and switch expressions, and added the ability to discard task groups.

Swift 5.10 (Mar 2024) closes all known static data-race safety holes in complete strict concurrency checking. It introduces strict concurrency for global variables which prevents data races when using global and static variables. It also brings in isolated default value expressions which closes a data-race safety hole that previously permitted isolated default stored property values to be synchronously evaluated from outside the actor.

Swift 6 will build upon this base. Let’s dive into its most noticeable features.

Expression macro as caller-side argument

User-defined macros can now be used as a default argument, just like built-in macros. When user-defined macros are used as default arguments they are expanded at the call site; whereas when they are used as sub-expressions of default arguments, they are expanded at the place they are written. For example, consider the following functions using the #MyFileID macro.

Here is how the macro is expanded when it gets called from the app code.

Pack Iteration

Swift 5.9 introduced parameter value and type parameter packs, which made it possible to write generic functions that accept an arbitrary number of arguments with distinct types. The most noticeable impact was that the 10 view limit in SwiftUI is removed. With Swift 6, we can now iterate over a value pack with for-in loops. This is an advanced feature of Swift and it may significantly impact SwiftUI APIs.

Tuples Conform to Equatable, Comparable, and Hashable

Since tuples lacked the ability to conform to protocols, many developers stopped using tuples altogether in favor of structs that can conform to protocols. Tuples now conform to Equatable, Comparable and Hashable if their elements conform to the said protocols.

Typed throws

Errors in Swift are always type-erased to any Error, which encourages writing generalized error handling code. Once SE-413 has been implemented, functions and closures can throw concrete error types.

Conclusion

The release of Swift 6 is a great milestone for converting your Objective-C apps to Swift, if you haven’t already done so. Switching to Swift allows for the use of brand new frameworks like SwiftUI, SwiftData, RegexBuilder, Algorithms, etc., which makes developing apps faster and easier.

According to “The State of Developer Ecosystem 2023” survey by JetBrains, “Objective-C is objectively retired”. Objective-C has lost two-thirds of its users in the last six years, and in the past year only 2% of the respondents used it in 2023. Also, according to this study on Apple’s use of Swift and SwiftUI in Apple’s binaries, the usage of SwiftUI grew by 70%, while Swift usage grew by 50% from iOS 16 to iOS 17.

It is clear that the community of Objective-C developers is shrinking, and Apple is gradually gravitating toward Swift in their internal binaries; hence it is a good idea to start migrating to Swift. Migration to Swift also allows for the adoption of SwiftUI and enables your apps to target all Apple platforms.

References

Apple’s use of Swift and SwiftUI in iOS 17
On the road to Swift 6

SE-0283: Tuples Conform to Equatable, Comparable, and Hashable
SE-0422: Expression macro as caller-side default argument
SE-0408: Pack Iteration
SE-0413: Typed throws
Swift Changelog
The State of Developer Ecosystem 2023
What’s new in Swift?

--

--