The if #available(macOS 26, *) { … } checks required to call newer APIs from apps that still run on older OSes are really cumbersome to use in SwiftUI.

This technique from @davedelong makes this much nicer and easier: https://davedelong.com/blog/2021/10/09/simplifying-backwards-compatibility-in-swift/

You might still have to do some manual mapping of enums and constants, but that ugliness is contained, leaving your call sites clean.

Simplifying Backwards Compatibility in Swift

Every year as new OS and Swift versions are released, the question comes up over and over again: “how do I use this new thing while also supporting older versions?”. While we have a bunch of “availability” tools at our disposal (and I’ll be using them in this post), they always come across as somewhat cumbersome: we need to do inline checks, or we have conditional logic flow that obfuscates the intent of some of our code, and so on.

Dave DeLong

Since the dawn of SwiftUI, I've been using the (ill-advised, for multiple reasons) custom `if` view modifier as a last resort, which uses basically the same technique as the @davedelong's "Backport" system (with the same downsides, I imagine).

But you can't put an #available(…) check inside an `if` view modifier, and I've been annoyed by this for years. It turns out I just needed to make a slight change to make this work. 🙏

If you’re an iOS dev, and you don’t want to write your own, check out https://github.com/superwall/iOS-Backports
GitHub - superwall/iOS-Backports: SwiftUI-Backports makes it easy to use the latest SwiftUI modifier, like those introduced in iOS 26, while still supporting older iOS versions. With a simple .backport modifier, you can write modern SwiftUI code without wrapping every new API in #available checks. It’s lightweight, drop-in ready, and keeps your UI code clean and future-proof.

SwiftUI-Backports makes it easy to use the latest SwiftUI modifier, like those introduced in iOS 26, while still supporting older iOS versions. With a simple .backport modifier, you can write moder...

GitHub

@siracusa I have heard very good things about this one too, just in case: https://github.com/shaps80/SwiftUIBackports

(Unsure if it uses the same techniques)

GitHub - shaps80/SwiftUIBackports: A collection of SwiftUI backports for iOS, macOS, tvOS and watchOS

A collection of SwiftUI backports for iOS, macOS, tvOS and watchOS - shaps80/SwiftUIBackports

GitHub
@mattiem @siracusa Hey I'm the developer of SwiftUIBackports. I do indeed use the same approach, Dave and I discussed that approach when we first wrote about it. I have a lot more back ports since I started earlier, but this new lib has a bunch I haven't gotten around to, I'd love to get them contributed if you'd like to contribute? Great work, either way 👍
@shaps I see an iOS folder, but no macOS folder. Are all the existing backports for iOS?
@siracusa the iOS folder is just for iOS specific areas. Everything otherwise is the same platforms supported by the original apis. It’s designed to be drop. I have a separate lib SwiftUIPlus that adds really convenient pieces but the backports always stick to the platforms and api of the original design.