# @available and #available

**URL:** <https://forums.swift.org/t/available-and-available/90062>\
**Category:** Using Swift\
**Created:** [October 14, 2026, 8:53pm UTC](https://forums.swift.org/t/available-and-available/90062 "2026-10-14T20:53:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [October 14, 2026, 8:53pm UTC](https://forums.swift.org/t/available-and-available/90062/1 "2026-10-14T20:53:17Z")

</div>

### Overview

- There is an enum `Engine` in the framework which has a case only available iOS 27 onwards
- I have an enum `Car` which uses the `Engine` in a `switch` statement

### Question

- Is there a better way to implement `Car.engine`?
- Is there a way to define 2 Car types depending on if the iOS version is 27 or higher or if it is lower than 27?
- Or is there an alternate approach to solving this?

### Problem

- Since `Engine.electric` and `Car.green` are only available iOS 27.0 onwards is there a way to avoid `if #available(iOS 27.0, *)` inside engine computed property?
- The reason is I feel `engine` would never return `hybrid` but I just have it there to make it compile

### Code

```swift
// Defined in the framework, I have no control over this
enum Engine {
    @available(iOS 27.0, *)
    case electric
    case combustion
    case hybrid
    case aircraftEngine
    case shipEngine
    // many more cases
}

// Type defined by me
enum Car {
    @available(iOS 27.0, *)
    case green
    case orange

    var engine: Engine {
        switch self {
        case .green:
            if #available(iOS 27.0, *) {
                .electric
            } else {
                .hybrid
            }
        case .orange:
            .combustion
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [October 14, 2026, 10:28pm UTC](https://forums.swift.org/t/available-and-available/90062/2 "2026-10-14T22:28:38Z")

</div>

Assuming it doesn't get reverted for some reason, with a future version of the Swift compiler you won't have to write `if #available(iOS 27.0, *)` in the body of `case .green` because the compiler will infer it for you. See [#46662](https://github.com/swiftlang/swift/issues/46662) (and the fix [here](https://github.com/swiftlang/swift/pull/89724)).

Although looking more closely at your actual example, you're using a switch expression rather than a switch statement, which this enhancement doesn't work for yet. But I hope to address that in the same release.

In the meantime, you just have to write the `if #available(iOS 27.0, *)` in the case body.

---

<div class="post-metadata">

**Author:** ![fpseverino](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/fpseverino/32/35868_2.png) [@fpseverino](https://forums.swift.org/u/fpseverino)\
**Post date:** [October 14, 2026, 11:06pm UTC](https://forums.swift.org/t/available-and-available/90062/3 "2026-10-14T23:06:30Z")

</div>

This would be huge, I’ve come across it multiple times, both with switch expressions and switch statements

---

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [October 14, 2026, 11:12pm UTC](https://forums.swift.org/t/available-and-available/90062/4 "2026-10-14T23:12:17Z")

</div>

Thanks @tshortli, I am not sure if I am missing something.

Is this available in Swift 6.4 (Xcode 27)?

Following throws a compilation error:

I have taken the same example and changed to iOS 27 instead of macOS 26.

Error: `'f()' is only available in iOS 27.0 or newer`

```swift
@available(iOS 27.0, *)
func f() -> Int { 0 }

enum E {
  @available(iOS 27.0, *)
  case a
}

func multiplex(_ e: E) -> Int {
  switch e {
  case .a:
    return f() // 'f()' is only available in iOS 27.0 or newer
  }
}

```

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [October 14, 2026, 11:27pm UTC](https://forums.swift.org/t/available-and-available/90062/5 "2026-10-14T23:27:36Z")

</div>

> [@somu](#):
>
> Thanks @tshortli, I am not sure if I am missing something.
> 
> Is this available in Swift 6.4 (Xcode 27)?

It's not in Swift 6.4. It should become available in the next release.

Edit: If you're curious, you could try with the latest development snapshot or [Godbolt](https://godbolt.org/z/oEKazqhxs).

---

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [October 14, 2026, 11:28pm UTC](https://forums.swift.org/t/available-and-available/90062/6 "2026-10-14T23:28:52Z")

</div>

Thanks a ton @tshortli this fix would be very useful!!!

---

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [October 14, 2026, 11:42pm UTC](https://forums.swift.org/t/available-and-available/90062/7 "2026-10-14T23:42:09Z")

</div>

Thanks a lot @tshortli that's a nice website to test different compiler versions.

Following code works fine with no compilation errors:

```swift
// Defined in the framework, I have no control over this
enum Engine {
    @available(iOS 27.0, *)
    case electric
    case combustion
    case hybrid
    case aircraftEngine
    case shipEngine
    // many more cases
}

// Type defined by me
enum Car {
    @available(iOS 27.0, *)
    case green
    case orange

    var engine: Engine {
        switch self {
        case .green:
            .electric
        case .orange:
            .combustion
        }
    }
}

```
