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

# Background indexing

> How the Rollup SDK starts indexing, continues it in the background, and keeps the index up to date.

The SDK decides when to index. You start it once, with the person's Photos grant, and it keeps the index up to date from then on.

## The first index

When the person grants Photos access through `requestPhotoAccess`, the first index starts at once. Because the grant is the person's own action, the SDK asks iOS to let the run continue in the background (a continued processing task). If the person leaves your app, iOS keeps the run going and shows its progress in a system UI, which uses the title you set in `backgroundProgress`.

If Photos access was granted at an earlier launch, and the index is missing or unfinished, the SDK indexes while your app is on screen.

You can also start or continue indexing from a button with `indexing.start()`. Call it from a tap: iOS only accepts continued processing that a person started.

```swift theme={null}
Button("Continue in the background") {
    Rollup.shared.indexing.start()
}
```

## Keeping the index up to date

With `updatesAutomatically` on, the SDK adds new photos:

* **While your app is on screen**, shortly after the library changes, when the network comes back, when the window moves to a new day, or when you change options.
* **In the background**, with a background processing task (`<bundle ID>.rollup.update`). It also finishes an index that was not finished. It has no charging or network requirement; iOS chooses when it runs, usually when the iPhone is idle.

Only new photos are indexed. The SDK does not rebuild what it already holds.

## What iOS controls

* **The person can stop** continued processing from the system UI.
* **Slow progress** can make iOS ask the person whether to continue, and iOS can end the task if they do not answer or if the system is under load.
* **Background work is slower.** iOS runs indexing several times slower off screen than on screen.
* **Background processing tasks** run when iOS decides, which may be hours later or overnight.

When your app leaves the screen without a background task, the SDK stops the run safely before iOS suspends the app, and a later run picks up where it stopped. After a failed run, the SDK waits 10 minutes before starting another automatic run.

## Showing progress

Show the person what is happening with `indexing.states`. Search works as soon as the first slice is finished, so you can show results before indexing is done.

```swift theme={null}
for await state in Rollup.shared.indexing.states {
    if case .indexing(let indexed, let total, let searchable) = state {
        progressLabel = "Getting to know your photos: \(indexed) of \(total)"
        searchButtonEnabled = searchable
    }
}
```

See [IndexingState](/reference/indexing-state) for every state.


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