Skip to main content

SwiftUI Integration

A complete example showing SpendOwl integration in a SwiftUI app.

Project Setup

1

Add SpendOwl Package

In Xcode, go to File → Add Package Dependencies and add:
2

Create App Entry Point

Configure SpendOwl in your App.init().
3

Access Attribution

Use try await SpendOwl.attribution() in your views.

Complete Example

App.swift

Configure SpendOwl when the app launches:

ContentView.swift

Display attribution data and manage user identity:

Key Patterns

Task-based Attribution

Use Swift’s Task to fetch attribution asynchronously:

Observable Pattern

For a more robust architecture, use an @Observable class:

Authentication Flow

Set user ID after login:

Download Example

The complete example project is available on GitHub:

SpendOwlDemo-SwiftUI

Download the complete SwiftUI example