🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API client / Getting started / Initialize

Initialize the Swift API client

Before you can index your data or search your Algolia indices, you must initialize a search client with your application ID and API key. You can find both in your Algolia account.

If you’re building native apps for mobile devices, don’t include the API key directly in your source code. Because mobile apps aren’t updated as frequently, create API keys on your server and fetch them when the app starts.

Initialize the search client

The search client handles authentication and lets you manage your indices, for example, add data to them, or search them.

1
2
3
4
import AlgoliaSearchClient

let client = SearchClient(appID: "YourApplicationID", apiKey: "YourWriteAPIKey")
let index = client.index(withName: "your_index_name")

Replace your_index_name with the name of the index you want to use. You can find your existing indices in the Algolia dashboard or using the listIndices method. If the index doesn’t exist, a new, empty index is created locally. It’s created on Algolia’s servers only if you add records to the index.

Don’t use sensitive or personally identifiable information as your index name, including usernames, IDs, or email addresses. Index names are publicly shared.

Operations that are scoped to your Algolia application through the client are:

Operations scoped to an index are:

The Recommend, Personalization, Insights, and A/B testing APIs come with their own clients:

Did you find this page helpful?