@available question (again)

I once posted a question in the forums, but it seems I cannot find the thread now (maybe the thread was before the new forums was born).

I don't know why I am so confused about this directive (or whatever):

  1. It looks like a compiler directive because it has a specific syntax.
  2. But it also looks like it's a runtime check because it is used in if statement (not in #if).

So my question is: Given the following code:

if (@available(macOS 13.0, *) {
    NSLog("Running on macOS Ventura or later")
} else {
    NSLog("Running on older version before Ventura")
}

Does this directive check real macOS version during runtime?

Answered by Claude31 in 751070022

@available(macOS 13.0, *) is a compile time, restrictions depending on the minimum version.

Get details here: https://forums.swift.org/t/if-vs-available-vs-if-available/40266

Accepted Answer

@available(macOS 13.0, *) is a compile time, restrictions depending on the minimum version.

Get details here: https://forums.swift.org/t/if-vs-available-vs-if-available/40266

@available question (again)
 
 
Q