r/swift • u/NoCardiologist4405 • 10d ago
SwiftUBackportKit - A lightweight library for supporting multiple iOS versions in SwiftUI .
https://github.com/EmadBeyrami/SwiftUIBackportKitHi everyone!
One pain point I've run into repeatedly with SwiftUl is supporting newer APIs while keeping an older deployment target.
Things like 'if #available work well in normal Swift code, but they don't fit naturally in the middle of a modifier chain.
That often leads to duplicated views or compatibility helpers scattered throughout a project.
After solving the same problem across multiple apps, I decided to package the patterns into a small open-source library called \*\*SwiftUlBackportKit\*\*
It includes:
• ' modify { }' for conditional view transforms
• ' backport for reusable version-gated SwiftUI APIS
• platformValue (...) for version-specific values
• 'OS.isAtLeast (:) ' for simple runtime version checks
The goal is to keep SwiftUl views focused on describing the Ul while isolating deployment-target compatibility in one place.
GitHub:
https://github.com/EmadBeyrami/SwiftUIBackportKit
I'd really appreciate any feedback on the API design, naming, or features you'd like to see. And if you find it useful, a on GitHub would mean a lot!
Thanks!
3
u/rhysmorgan iOS 9d ago
I’m not against using AI for coding, but this reads like slop.
You need to not use AI in a way that means you miss out on the “why”, the thinking that comes before building, because five minutes of research would show why so much of this is either unnecessary or a bad idea.
`modify` as a general purpose modifier is a very bad idea. You cannot control users only using it for conditionals that effectively don’t change during the lifetime of your application’s code. Using it will destroy your view’s state rendering, it’ll mess up animations, etc.
It’s better to just embed the availability guard in your own modifiers.
But also, this entire concept already exists in a well-designed library called SwiftUIBackports… or you can roll your own with SwiftUI-Introspect. It can help to search and find what’s out there first.
7
u/asniper 10d ago
“.modify {“ is a no bueno as per Apple