shaps80/swiftuibackports
Use modern SwiftUI APIs while still supporting older Apple platforms.
Sponsor
Building useful libraries like these, takes time away from my family. I build these tools in my spare time because I feel its important to give back to the community. Please consider Sponsoring me as it helps keep me working on useful libraries like these 😬
You can also give me a follow and a 'thanks' anytime.
[[Twitter]](http://twitter.com/shaps)
Usage
SwiftUIBackports mirrors Apple's SwiftUI APIs where practical, while keeping backported APIs easy to find and remove once your deployment target reaches the native API.
View modifiers are available from .backport:
sheetContent
.backport.presentationDetents([.medium, .large])Backported types are usually available from the Backport namespace:
Backport.LabeledContent("", value: 0)If the compiler needs the fully-qualified namespace, use Backport<Any>:
Backport<Any>.LabeledContent("", value: 0)Environment backports use a backport prefix:
@Environment(\.backportRequestReview) private var requestReviewBackports
The supported backports are indexed in:
skills/swiftui-backports/references/Backports.jsonlThe line-oriented index lists implemented backports, their kind, source location, and platform availability. Prefer this index over static README examples, which get stale quickly.
This repository also includes an agent skill:
skills/swiftui-backports/SKILL.mdUse that skill when working in an app that targets older Apple OS versions, or when a compiler availability error blocks use of a newer SwiftUI API. The skill tells agents to:
- check the project deployment target
- search the bundled backport index
- prefer native SwiftUI when the deployment target is new enough
- use
.backport,Backport, orbackportenvironment keys when a matching backport exists
Installation
You can install manually (by copying the files in the Sources directory) or using Swift Package Manager (preferred)
To install using Swift Package Manager, add this to the dependencies section of your Package.swift file:
.package(url: "https://github.com/shaps80/SwiftUIBackports.git", .upToNextMajor(from: "2.0.0"))
Package Metadata
Repository: shaps80/swiftuibackports
Default branch: main
README: README.md