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

# Conditional display in InstantSearch iOS

> Learn how to improve your InstantSearch iOS app when there are no results, when there's no query, or when there are errors.

<Info>
  Starting May 1, 2024,
  Apple requires all iOS apps to include a privacy manifest.
  For more information, see [Privacy manifest](/doc/guides/building-search-ui/resources/privacy-manifest/ios/).
</Info>

This guide describes what to do when there are [no results](#handling-no-results),
when there's [no query](#handling-empty-queries), or when there are [errors](#handling-errors).
**Sometimes, though, users may not get any hits if their device [can't access the network or the network connection is slow](/doc/guides/building-search-ui/ui-and-ux-patterns/pagination/ios#no-hits-or-is-the-search-still-in-progress).**

If you want to feature content in your search results based on a set of conditions, you can use Algolia Rules to:

* [Feature specific data from within your records](https://www.algolia.com/ecommerce-merchandising-playbook/merchandise-search-results-page/) to, for example, show promotional prices during a sales period
* [Display advertisements or promotional banners](/doc/guides/managing-results/rules/merchandising-and-promoting/how-to/add-banners).

<Info>
  To learn how to suppress InstantSearch's initial search query,
  see [Conditional requests](/doc/guides/building-search-ui/going-further/conditional-requests/ios).
</Info>

## Handling no results

Since not all queries lead to results, it's essential to let users know when this happens by **providing hints on how to adjust the query.**

### Display a message

The easiest way to display a fallback message when a query doesn't return results is to subscribe to the [`Searcher`](/doc/api-reference/widgets/instantsearch/ios)'s `onResponse` event and show your "no results" UI whenever the response has no `hits`.

```swift Swift icon=code theme={"system"}
searcher.onResults.subscribe(with: self) { (_, results) in
    if results.hits.isEmpty {
        showNoResultsUI()
    } else {
        hideNoResultsUI()
    }
}
```

## Handling empty queries

By default, InstantSearch always shows you results, even when the query is empty. Depending on your use case and how you build your UI, you may only want to show results when there's a query.

The [`Hits`](/doc/api-reference/widgets/hits/ios) widget exposes a `showItemsOnEmptyQuery` property in the `HitsInteractor`'s initializer, which defaults to `true`. When set to `false`, the widget doesn't present hits if the query is empty.

```swift Swift icon=code theme={"system"}
let hitsInteractor = HitsInteractor<JSON>(showItemsOnEmptyQuery: false)
```

## Handling errors

If an error occurs, you can display a specific piece of content to help users return to the standard state.

To be notified of errors, subscribe to the [`Searcher`](/doc/api-reference/widgets/instantsearch/ios)'s `onError` event.

```swift Swift icon=code theme={"system"}
searcher.onError.subscribe(with: self) { (_, args) in
    let (_, error) = args
    debugPrint("Error occured\(error)")
}
```
