Objective-C API availability checks give wrong results

It turns out it IS a runtime/compile-time thing, but not that simple.

if (@available(...)) in Objective-C should be a runtime check, just like its swift equivalence if #available(...). But the compiler optimizes the else branch out in release builds, because it assumes the program will only be deployed on the same version of macOS where the compilation happens.

To force the compiler to do the check at runtime one must tell the compiler that the program could run on an older macOS by setting the MACOSX_DEPLOYMENT_TARGET environment variable.

1 Like