TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
@available attribute is a declaration attribute used to specify the platform, operating system version, or Swift language version required to access a specific declaration. It instructs the compiler to enforce API availability checks against the project’s minimum deployment target or the active Swift compiler version, emitting errors or warnings if a declaration is referenced in an unsupported context.
Syntax Forms
The attribute supports two primary syntactic forms: a shorthand list for basic version gating, and a detailed list for granular lifecycle management.Shorthand Syntax
Used to declare the minimum required operating system versions across one or more platforms simultaneously.platform: A recognized operating system platform identifier (e.g.,iOS,macOS,tvOS,watchOS,visionOS, ormacCatalyst). Theswiftlanguage identifier is not permitted in shorthand syntax.version: A version number formatted asmajor,major.minor, ormajor.minor.patch.*(Wildcard): A mandatory token in the shorthand syntax. It indicates that the declaration is available on all other platforms not explicitly listed, inheriting the project’s minimum deployment target for those platforms.
Detailed Lifecycle Syntax
Used to define the complete lifecycle of a declaration on a specific platform or for a specific Swift language version, including deprecation and obsolescence.platform: A specific OS platform identifier, theswiftlanguage identifier, or the*wildcard.- Swift Language Gating: To restrict a declaration by the Swift compiler version, the
swiftidentifier must be used within this detailed syntax (e.g.,@available(swift, introduced: 5.1)or@available(swift, obsoleted: 4.2)). - Wildcard Restriction: When using the
*wildcard in the detailed syntax, it applies the modifiers unconditionally across all platforms. However, the*wildcard cannot be combined with versioned arguments (introduced,obsoleted, ordeprecated: version). It can only be used with unversioned modifiers (e.g.,@available(*, deprecated, message: "Use new API")or@available(*, unavailable)).
- Swift Language Gating: To restrict a declaration by the Swift compiler version, the
Lifecycle Modifiers
When using the detailed syntax, the compiler evaluates the following comma-separated arguments:introduced: version: Defines the first version of the specified platform or Swift language where the declaration is accessible.deprecated: version: Defines the version where the declaration remains accessible but is no longer recommended. The compiler emits a warning when the declaration is referenced. If theversionis omitted (e.g.,deprecated), it is treated as unconditionally deprecated on that platform.obsoleted: version: Defines the version where the declaration is entirely removed from the API surface. The compiler emits an error if referenced. An obsoleted declaration cannot be used, even if the deployment target is higher than theintroducedversion.message: "string": A string literal that the compiler appends to the diagnostic warning or error emitted bydeprecated,obsoleted, orunavailable.renamed: "string": A string literal providing the new name of the declaration. The compiler uses this to generate a Fix-It action in the IDE.
Absolute Unavailability
The attribute can explicitly forbid the use of a declaration on specific platforms using theunavailable argument.
unavailable is present, introduced, deprecated, and obsoleted cannot be used in the same attribute block.
Application Scope
The@available attribute can be applied to almost any top-level or nested declaration in the Swift Abstract Syntax Tree (AST), including:
- Classes, Structs, and Enums
- Protocols and Associated Types
- Functions, Methods, and Initializers
- Properties and Subscripts
- Extensions
@available attributes can be stacked on a single declaration to define complex availability matrices across different platforms and language versions.
Attribute vs. Condition
The@available attribute is strictly declarative and applies to API definitions. It is distinct from the #available and #unavailable conditions (which are compiler control statements). Conditions are evaluated at runtime within control flow statements (like if or guard) to safely execute code paths based on the host environment.
Master Swift with Deep Grasping Methodology!Learn More





