Swift 5.8 is now officially released! ๐ This release includes major additions to the language and standard library, including hasFeature to support piecemeal adoption of upcoming features, an improved developer experience, improvements to tools in the Swift ecosystem including Swift-DocC, Swift Package Manager, and SwiftSyntax, refined Windows support, and more.
Thank you to everyone in the Swift community who made this release possible. Your Swift Forums discussions, bug reports, pull requests, educational content, and other contributions are always appreciated!
For a quick dive into some of whatโs new in Swift 5.8, check out this playground put together by Paul Hudson.
The Swift Programming Language book has been updated for Swift 5.8 and is now published with DocC. This is the official Swift guide and a great entry point for those new to Swift. The Swift community also maintains a number of translations.
Swift 5.8 enables you to start incrementally preparing your projects for Swift 6 by using upcoming features. By default, upcoming features are disabled. To enable a feature, pass the compiler flag -enable-upcoming-feature followed by the featureโs identifier.
Feature identifiers can also be used in source code using #if hasFeature(FeatureIdentifier) so that code can still compile with older tools where the upcoming feature is not available.
Swift 5.8 includes upcoming features for the following Swift evolution proposals:
ConciseMagicFile)ForwardTrailingClosures)ExistentialAny)BaseSlashRegexLiterals)For example, building the following file at /Users/example/Desktop/0274-magic-file.swift in a module called MagicFile with -enable-experimental-feature ConciseMagicFile will opt into the concise format for #file and #filePath described in SE-0274:
print(#file)
print(#filePath)
fatalError("Something bad happened!")
The above code will produce the following output:
MagicFile/0274-magic-file.swift
/Users/example/Desktop/0274-magic-file.swift
Fatal error: Something bad happened!: file MagicFile/0274-magic-file.swift, line 3
Swift 5.8 also includes conditional attributes to reduce the maintenance cost of libraries that support multiple Swift tools versions. #if checks can now surround attributes on a declaration, and a new hasAttribute(AttributeName) conditional directive can be used to check whether the compiler version has support for the attribute with the name AttributeName in the current language mode:
Swift 5.8 brings other language and standard library enhancements, including unboxing for any arguments to optional parameters, local wrapped properties in result builders, improved debug printing for key paths, and more.
You can find the complete list of Swift Evolution proposals that were implemented in Swift 5.8 in the Swift Evolution Appendix below.