.package(url: "https://github.com/Meginhufr/brua-swift", from: "0.1.0")iOS and macOS
BruaKit for Swift: the models, the selection rule, request hints and a SwiftUI view. iOS 16 and macOS 13 or later.
Install
Add the package with Swift Package Manager, in Xcode under File → Add Package Dependencies with the repository URL, or in Package.swift:
.package(url: "https://github.com/Meginhufr/brua-swift", from: "0.1.0")and BruaKit as a dependency of your target.
Point it at your organization
One client per app, with your organization's base URL on the edge. The examples use Brua's own organization; yours is on the Integrate page of the back office, or comes from the colleague who set Brua up.
import BruaKit
let brua = BruaClient(base: URL(string: "https://cdn.brua.dev/assets/991ceed8-a70e-4a5f-b3d3-e0b6b3d93e44")!)The client reads each asset from the edge with no key. URLSession's cache keeps it for the edge's minute, so a merge in Brua reaches the screen within that minute with no release of yours.
Render by id
// Follows dark mode, Reduce Motion and the display scale; the alt text is the VoiceOver label.
// The placeholder shows until the asset has loaded, and when nothing is released under the id.
BruaImage(id: "bridge", client: brua)
.frame(width: 320)A snapshot your backend embedded in its own JSON decodes with your other models and renders the same way:
struct Campaign: Decodable {
let title: String
let hero: AssetResponse
}
BruaImage(campaign.hero)
.frame(width: 320)To choose the file yourself, for a custom loader or a widget:
let url = VariantSelector.url(for: campaign.hero, client: ClientState(colorScheme: .dark, scale: 3, targetWidth: 320))What you get
- Light and dark from the system, switching without a new request.
- The still of an animation under Reduce Motion, and as the placeholder while an animation loads. To play Lottie or Rive, add their type to
supportedTypesand give those variants to the player. - The scale the display needs, in the format the device decodes.
- The alt text as the VoiceOver label, in the device's language; decorative assets are skipped.
- A merge in Brua reaches the app within a minute, with no release of yours.
Next
- Keep the ids typed:
brua pull Assets.swiftwrites the released ids as constants. - Backends: forwarding the device's hints when your backend reads the delivery API.
- The lifecycle of an asset: what a merge changes, and when.