Brua
Install
.package(url: "https://github.com/Meginhufr/brua-swift", from: "0.1.0")
GitHub: Meginhufr/brua-swift

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:

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.

Swift
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

Swift
// 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:

Swift
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:

Swift
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 supportedTypes and 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