Is there really no Swift equivalent to #if defined(MAC_OS_VERSION_XX_X)?

A regression found in Xcode 26 Beta has forced me into a situation where I have to use Xcode 16.4 and Xcode 26 Beta side-by-side to compile the same sources.

This implies the same sources are compiled against the macOS 15 SDK and macOS 26 SDKs, depending on which Xcode version I’m using. In C/C++/Obj-C files, any use of symbols found only in the macOS 26 SDK can be bracketed within an #if defined(MAC_OS_VERSION_26_0) which keeps the resulting file compilable against the older SDK.

But in Swift? The #if os(mac) expression doesn’t support a version parameter… and there doesn’t seem to be an #if sdk(…) either. Are there alternative techniques? Older posts about this topic don’t suggest anything useful and they are 5 years old.

(I hope the question makes it clear that a runtime check via #available(macOS 26, *) statement wouldn’t really work here.)

Thanks!

#if compiler(>=6.2)

This gets discussed around this time every year, it feels like. Here's some relevant progress from a few years ago, and AFAIK nothing has happened since:

2 Likes

So piggybacking on compiler version if it happens to be in lockstep with SDK version is still the best we can do. I can’t even. (Thank you for nudging me in the right direction.)

1 Like