Documentation • Community Forum • Stack Overflow • Report a bug • Support
✨ Features
- The Swift client is compatible with Swift 5 and higher.
- It relies on the open source Swift libraries for seamless integration into Swift projects:
- Asynchronous and synchronous methods to interact with Algolia's API
- Thread-safe clients
- Typed requests and responses
- Injectable HTTP client
Install
Swift 5.0+
- Add a dependency on InstantSearchClient:
- CocoaPods
- add
pod 'AlgoliaSearchClientSwift', '~> 8.0.0-beta.4'
to yourPodfile
.
- add
- Carthage
- add
github "algolia/algoliasearch-client-swift" ~> 8.0.0-beta.4
to yourCartfile
. - launch the following commands from the project directory
carthage update ./Carthage/Checkouts/algoliasearch-client-swift/carthage-prebuild carthage build
- add
- Swift Package Manager
- add
.package(name: "AlgoliaSearchClientSwift", url: "https://github.com/algolia/algoliasearch-client-swift", from: "8.0.0-beta.4")
to your package dependencies array inPackage.swift
- add
AlgoliaSearchClientSwift
to your target dependencies.
- add
- CocoaPods
- Add
import AlgoliaSearchClientSwift
to your source files.
Swift 4.2
- Add a dependency on InstantSearchClient:
- CocoaPods
- add
pod 'InstantSearchClient', '~> 6.0'
to yourPodfile
.
- add
- Carthage:
- add
github "algolia/algoliasearch-client-swift" ~> 6.0.0
to yourCartfile
.
- add
- Swift Package Manager:
- add
.package(url:"https://github.com/algolia/algoliasearch-client-swift", from: "6.0.0")
to your package dependencies array inPackage.swift
- add
InstantSearchClient
to your target dependencies.
- add
- CocoaPods
- Add
import InstantSearchClient
to your source files.
Swift 4.1
- Add a dependency on InstantSearchClient:
- CocoaPods:
- add
pod 'InstantSearchClient', '~> 5.0'
to yourPodfile
.
- add
- Carthage:
- add
github "algolia/algoliasearch-client-swift" ~> 5.0.0
to yourCartfile
.
- add
- Swift Package Manager:
- add
.package(url:"https://github.com/algolia/algoliasearch-client-swift", from: "5.0.0")
to your package dependencies array inPackage.swift
- add
InstantSearchClient
to your target dependencies.
- add
- CocoaPods:
- Add
import InstantSearchClient
to your source files.
💡 Getting Started
Initialize the client
To start, you need to initialize the client. To do this, you need your Application ID and API Key. You can find both on your Algolia account.
let client = Client(appID: "YourApplicationID", apiKey: "YourAdminAPIKey")
let index = client.index(withName: "your_index_name")
Push data
Without any prior configuration, you can start indexing contacts in the contacts
index using the following code:
struct Contact {
let firstname: String
let lastname: String
let followersCount: Int
let company: String
let objectID: String
}
let index = client.index(withName: "contacts")
let contact = Contact(firstname: "Jimmie",
lastname: "Barninger",
followersCount: 93,
company: "California Paint",
objectID: "one")
try index.saveObject(contact)
Search
You can now search for contacts by firstname
, lastname
, company
, etc. (even with typos):
// Synchronous search
let searchResponse = try index.search(query: "jimmie")
// Asynchronous search
index.search(query: "jimmie") { result in
switch result {
case .failure(let error):
...
case .success(let searchResponse):
...
}
}
For full documentation, visit the Algolia Swift API Client's documentation.
📝 Examples
You can find code samples in the Algolia's API Clients playground.
📄 License
Algolia Swift API Client is an open-sourced software licensed under the MIT license.