> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift Available Attribute

The `@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.

```swift theme={"dark"}
@available(platform version, platform version, *)
```

* **`platform`**: A recognized operating system platform identifier (e.g., `iOS`, `macOS`, `tvOS`, `watchOS`, `visionOS`, or `macCatalyst`). The `swift` language identifier is **not** permitted in shorthand syntax.
* **`version`**: A version number formatted as `major`, `major.minor`, or `major.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.

```swift theme={"dark"}
@available(platform, introduced: version, deprecated: version, obsoleted: version, message: "string", renamed: "string")
```

* **`platform`**: A specific OS platform identifier, the `swift` language identifier, or the `*` wildcard.
  * *Swift Language Gating:* To restrict a declaration by the Swift compiler version, the `swift` identifier **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`, or `deprecated: version`). It can only be used with unversioned modifiers (e.g., `@available(*, deprecated, message: "Use new API")` or `@available(*, unavailable)`).

## 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 the `version` is 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 the `introduced` version.
* **`message: "string"`**: A string literal that the compiler appends to the diagnostic warning or error emitted by `deprecated`, `obsoleted`, or `unavailable`.
* **`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 the `unavailable` argument.

```swift theme={"dark"}
@available(platform, unavailable, message: "string")
```

When `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

Multiple `@available` attributes can be stacked on a single declaration to define complex availability matrices across different platforms and language versions.

```swift theme={"dark"}
@available(macOS 12.0, *)
@available(iOS, introduced: 14.0, deprecated: 15.0, renamed: "newOperation()")
@available(swift, introduced: 5.5)
@available(watchOS, unavailable)
func legacyOperation() {
    // Implementation
}
```

## 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.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Swift Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
