> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tolt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift

> Claim partner codes and app links for your iOS and macOS app users.

The Tolt Swift package claims a partner's code for an app user. Tolt then credits that partner with the purchases [RevenueCat](https://docs.tolt.com/integrations/revenuecat.md) reports for the same user. See [Mobile apps](https://docs.tolt.com/tracking/mobile-apps.md) for how it fits together.

![](https://mintcdn.com/tolt-29/zzPkjqmWP80fP3qw/images/logos/swift.svg?fit=max\&auto=format\&n=zzPkjqmWP80fP3qw\&q=85\&s=304bdc03d80a13ee08cbfedc6036a71a) Tolt.claim
POST /client/claims
&#x20;Tolt

Sent by the SDK

**claim**requestapp\_user\_id"user\_8f2k"code"SAM20"first\_seen\_at"2026-11-04T09:30Z"

In Tolt

**customer**cus\_7Lm2…customer\_id"user\_8f2k"partner"sam"statuslead

## Install

Add the package in Xcode under **File → Add Package Dependencies**, or in `Package.swift`:

```swift Package.swift theme={"system"}
.package(
  url: "https://github.com/toltapp/tolt-swift",
  from: "0.2.0"
)
```

It supports iOS 15 and macOS 12 and later, and has no dependencies.

## Configure

Call `configure` once at launch with your public key from **Settings → Integrations** in the dashboard. The SDK remembers the first launch, which the program's [claim window](https://docs.tolt.com/tracking/mobile-apps.md#claim-rules) counts from.

```swift App.swift theme={"system"}
import Tolt

@main
struct MyApp: App {
  init() {
    Tolt.configure(publicId: "YOUR_PUBLIC_KEY")
  }

  var body: some Scene {
    WindowGroup { ContentView() }
  }
}
```

## Claim a code

Claim the code when the user enters one. Pass the app user id you give RevenueCat.

```swift Swift theme={"system"}
let result = try await Tolt.claim(
  code: "SAM20",
  appUserId: Purchases.shared.appUserID
)
```

Also store the code on the RevenueCat customer. If a purchase reaches Tolt before the claim, Tolt uses it to credit the partner.

```swift Swift theme={"system"}
Purchases.shared.attribution.setAttributes(
  Tolt.revenueCatAttributes(code: "SAM20")
)
```

## Claim from a link

When a [partner app link](https://docs.tolt.com/tracking/mobile-apps.md#partner-app-links) opens your app with `tolt_click` or `tolt_code` in the URL, pass the URL on. It returns `nil` for links without either.

```swift Swift theme={"system"}
.onOpenURL { url in
  Task {
    _ = try await Tolt.claim(
      url: url,
      appUserId: Purchases.shared.appUserID
    )
  }
}
```

With a deep linking provider, read the click from its callback instead and call `Tolt.claim(clickId:appUserId:)`.

## Results and errors

`claim` returns a `ClaimResult` with a `status`:

| `status` | Meaning |
| - | - |
| `.claimed` | The user is now the partner's customer |
| `.alreadyClaimed` | The user already had a partner. Nothing changed |

It throws a `ToltError`:

| Error | When |
| - | - |
| `.notConfigured` | `configure` wasn't called |
| `.invalidInput(field)` | The code, click or app user id is empty |
| `.codeNotFound` | No active partner has this code or click, or the public key is wrong |
| `.codeConflict(message)` | Two partners share the code, or the claim window has closed |
| `.rateLimited` | Over 30 claims a minute from one IP |
| `.server(status:message:)` | Anything else |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.