Skip to content

Instantly share code, notes, and snippets.

@DandyLyons
Created November 19, 2024 00:24
Show Gist options
  • Select an option

  • Save DandyLyons/56dc43d0b98befa670758490b43fff07 to your computer and use it in GitHub Desktop.

Select an option

Save DandyLyons/56dc43d0b98befa670758490b43fff07 to your computer and use it in GitHub Desktop.
Swift `UpcomingFeature` enum
// Please feel free to add this gist to your own `Package.swift` file to enable quick type-safe Swift language feature flagging.
extension SwiftSetting {
/// Feature Flag Strings
///
/// Found at https://www.swift.org/migration/documentation/swift-6-concurrency-migration-guide/sourcecompatibility/
/// Please update this list as new feature flags are added.
enum UpcomingFeature: String {
/// SE-0418: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md
case inferringSendableFromCapture = "InferSendableFromCaptures"
/// SE-0423: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0423-dynamic-actor-isolation.md
case dynamicActorIsolation = "DynamicActorIsolation"
/// SE-0434: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0434-global-actor-isolated-types-usability.md
case globalActorIsolatedTypesUsability = "GlobalActorIsolatedTypesUsability"
}
/// Enable an upcoming feature flag, using a static type.
///
/// - Parameters:
/// - upcomingFeature: The feature flag to enable.
/// - condition: The condition under which the feature flag should be enabled.
/// If `nil`, the feature flag will always be enabled.
/// ## Usage
/// ```swift
/// let package = Package(
/// name: "MyLibrary",
/// products: [
/// .library(
/// name: "MyLibrary",
/// targets: ["MyLibrary"]),
/// ],
/// targets: [
/// .target(
/// name: "MyLibrary",
/// swiftSettings: [
/// .enableUpcomingFeature(.globalActorIsolatedTypesUsability)
/// ]
/// ),
///
/// ],
/// swiftLanguageVersions: [
/// .v5
/// ]
/// )
/// ```
static func enableUpcomingFeature(_ upcomingFeature: UpcomingFeature, condition: BuildSettingCondition? = nil) -> SwiftSetting {
enableUpcomingFeature(upcomingFeature.rawValue, condition)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment