swift_small_white Created with Sketch.

Getting Started

Supported platforms

Our Swift client is supported on iOS, macOS, tvOS and watchOS, and is usable from both Swift and Objective-C.

Install

  • add a dependency on AlgoliaSearch-Client-Swift:
    • CocoaPods: add pod 'AlgoliaSearch-Client-Swift', '~> 4.0' to your Podfile
    • Carthage: add github "algolia/algoliasearch-client-swift" to your Cartfile
  • add import AlgoliaSearch to your source files

Miscellaneous

You can browse the automatically generated reference documentation. (See also the offline-enabled version.)

<Welcome Objective-C developers>

In July 2015, we released a new version of our Swift client, able to work with Swift and Objective-C. As of version 3 (April 2016), Swift has become the reference implementation for both Swift and Objective-C projects. The Objective-C API Client is no longer under active development. It is still supported for bug fixes, but will not receive new features.

If you were using our Objective-C client, read the migration guide from Objective-C.

</Welcome Objective-C developers>

If you were using version 2.x of our Swift client, read the migration guide to version 3.x.

Init Index

To begin, you will need to initialize the client. In order to do this you will need your Application ID and API Key. You can find both on your Algolia account.

let client = Client(appID: "YourApplicationID", apiKey: "YourAPIKey")

The api key that is displayed here is your ADMIN API Key. To maintain security, never use your ADMIN API Key on your frontend or share it with anyone. In your frontend, use the SEARCH ONLY API Key or any other key that has search only rights.

If you are building a native app on mobile, be sure to not include the search API key directly in the source code. You should instead consider fetching the key from your servers during the app’s startup.