Using Upcoming Feature Flags

Beginning in Swift 5.8 you can flexibly adopt upcoming Swift features using a new compiler flag and compilation condition. This post describes the problem upcoming feature flags solve, their benefits, and how to get started using them in your projects.

swift.org/blog/using-upcoming-feature-flags/

Swift 5.8 introduces a flexible mechanism to adopt upcoming features via the -enable-upcoming-feature compiler flag and the hasFeature() condition, allowing developers to incrementally prepare for Swift 6 while maintaining source compatibility.

This addresses source-breaking changes, like the bare slash regex literal syntax from Swift 5.7, by enabling opt-in use through flags like -enable-upcoming-feature BareSlashRegexLiterals. In Xcode, flags are added to the "Other Swift Flags" build setting, while Swift Package Manager uses the .enableUpcomingFeature setting in manifests with tools version 5.8 or later.

The Swift Evolution Dashboard lists available flags, such as ConciseMagicFile, ForwardTrailingClosures, ExistentialAny, and BareSlashRegexLiterals, helping developers test and adopt features early to ease migration.


Category:

Tag:

Year: