Swift Feature Flags Reference

website·Indexed 32 days ago

https://flags.swiftythemes.com

A reference guide for Swift compiler flags used to enable upcoming and experimental language features. Includes version-specific lists for versions 5.9, 5.10, 6.0, 6.1, 6.2, 6.3, 6.4, and 6.5, with instructions on enabling features via Xcode Build Settings or command line arguments.

Tokens
13.7K
Snippets
52
Records
224
Agent score
53%

What's inside Swift Feature Flags

  1. Available Upcoming Feature Flags in Swift 6.5

    The following feature flags are categorized as 'Upcoming' in Swift 6.5. These typically represent features moving toward stability. To enable these, refer to the project's 'How to enable' documentation.

    Upcoming flags include:

    • BareSlashRegexLiterals
    • ConciseMagicFile
    • DeprecateApplicationMain
    • DisableOutwardActorInference
    • DynamicActorIsolation
    • ExistentialAny
    • ForwardTrailingClosures
    • GlobalActorIsolatedTypesUsability
    • GlobalConcurrency
    • ImmutableWeakCaptures
    • ImplicitOpenExistentials
    • ImportObjcForwardDeclarations
    • InferIsolatedConformances
    • InferSendableFromCaptures
    • InternalImportsByDefault
    • IsolatedDefaultValues
    • MemberImportVisibility
    • NonfrozenEnumExhaustivity
    • NonisolatedNonsendingByDefault
    • RegionBasedIsolation
    • StrictConcurrency
  2. Check for feature availability using the hasFeature directive

    You can programmatically determine if a specific compiler feature is enabled in your build using the #if hasFeature(...) directive. This allows for conditional compilation based on the presence of specific language or compiler features.
    #if hasFeature(StrictConcurrency)
    // Code for when StrictConcurrency is enabled
    #endif
  3. Available Experimental Feature Flags in Swift 6.5

    The following feature flags are categorized as 'Experimental' in Swift 6.5. These are early-stage features and may be subject to significant change. To enable these, refer to the project's 'How to enable' documentation.

    Experimental flags include:

    • AbstractStoredPropertyLayout
    • AccessLevelOnImport
    • AdditiveArithmeticDerivedConformances
    • AddressableParameters
    • AddressableTypes
    • AllowNonResilientAccessInPackage
    • AllowRuntimeSymbolDeclarations
    • AssumeResilientCxxTypes
    • BuiltinMacros
    • BuiltinModule
    • CalledAttribute
    • CheckImplementationOnly
    • CheckImplementationOnlyStrict
    • ClientBypassResilientAccessInPackage
    • ClosureBodyMacro
    • ClosureIsolation
    • CodeItemMacros
    • CompileTimeValues
    • CompileTimeValuesPreview
    • ConcurrencySyntaxSugar
    • ConsumeSelfInDeinit
    • CoroutineAccessors
    • CoroutineAccessorsUnwindOnCallerError
    • CoroutineFunctions
    • CustomAvailability
    • CxxImplementation
    • DebugDescriptionMacro
    • DefaultIsolationPerFile
    • DeprecateCompatMemberwiseInit
    • DeriveConformancesViaMacros
    • DifferentiableProgramming
    • DistributedActorResignRemoteID
    • DoExpressions
    • Embedded
    • EmbeddedDistributed
    • EmbeddedDynamicExclusivity
    • EnforceSPIOperatorGroup
    • Extern
    • ExtractConstantsFromMembers
    • FlowSensitiveConcurrencyCaptures
    • ForeignReferenceTypeSubclassing
  4. Check for feature availability using conditional compilation

    You can programmatically determine if a specific Swift feature is available in the current build environment using the #if directive with the hasFeature check.
    #if hasFeature(StrictConcurrency)
    // Code for when StrictConcurrency is enabled
    #endif
  5. Use stable language features in Swift 6.4

    The following features are marked as stable in Swift 6.4 and are available for use in production code:
    // Examples of stable features:
    // Actors: Use 'actor' for concurrency isolation
    // AsyncAwait: Use 'async' and 'await' for asynchronous programming
    // AttachedMacros: Use @Attached macro for code generation
    // BitwiseCopyable: Use the BitwiseCopyable protocol for low-level memory optimization
  6. Enable upcoming Swift 6.5 language feature flags

    The following feature flags are available in Swift 6.5 to enable experimental or upcoming language features. These flags allow developers to opt-in to specific proposals currently under development.

    Upcoming flags include:

    • ForExpressions
    • ForwardModeDifferentiation
    • FullTypedThrows
    • ImplicitLastExprResults
    • ImplicitSome
    • ImportMacroAliases
    • KeyPathWithMethodMembers
    • LifetimeDependence
    • Lifetimes
    • MoveOnlyClasses
    • MoveOnlyTuples
    • NamedOpaqueTypes
    • StaticAssert
    • StructLetDestructuring
    • TupleConformances
  7. Swift 6.1 Builtin Executor and Task flags

    Swift 6.1 provides several stable feature flags for low-level Builtin operations related to executors and task management, including:
    - BuiltinBuildExecutor
    - BuiltinBuildMainExecutor
    - BuiltinBuildTaskExecutorRef
    - BuiltinCreateTask (Builtin.createTask and Builtin.createDiscardingTask)
    - BuiltinCreateAsyncTaskWithExecutor
    - BuiltinExecutor (Builtin.Executor type)
    - BuiltinHopToActor
    - BuiltinTaskRunInline