# \#if vs @available vs if #available

**URL:** <https://forums.swift.org/t/if-vs-available-vs-if-available/40266>\
**Category:** Using Swift\
**Created:** [September 14, 2020, 2:55am UTC](https://forums.swift.org/t/if-vs-available-vs-if-available/40266 "2020-09-14T02:55:44Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![wowbagger](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/wowbagger/32/13847_2.png) [@wowbagger](https://forums.swift.org/u/wowbagger)\
**Post date:** [September 14, 2020, 2:55am UTC](https://forums.swift.org/t/if-vs-available-vs-if-available/40266/1 "2020-09-14T02:55:44Z")

</div>

What are the differences between `#if`, `@available`, and `if #available`, in terms of both compilation and use case?

Here is my understanding so far:

If I want to make a function available on macOS only, I can do it like this:

```swift
#if os(macOS)
func someMacOSOnlyFunction() { /* ... */ }
#endif

```

If I want to restrict it even further to some specific versions, I can do either of these 2:

```swift
@available(macOS 10.15, *)
func someMacOS15PlusOnlyFunction() { /* ... */ }

```

```swift
if #available(macOS 10.15, *) {
    func someMacOS15PlusOnlyFunction() { /* ... */ }
}

```

I know that the compiler ignores everything in `#if`, if the condition is not met. Does the compilation work likewise for `@available` and `if #available`? Does `@available` behave differently from `if #available` in any way? What are the best practices for choosing/using them?

---

_[View the full topic](https://forums.swift.org/t/if-vs-available-vs-if-available/40266)._
