Search API Client for Swift iOS

Features

  • Gives API access to all Algolia functionality, settings, advanced features, and ML/AI products
  • Pure cross-platform Swift client
  • Available via Cocoapods, Swift Package Manager, Carthage
  • Uses Result type and Codable protocol
  • Background retry strategy to ensure uptime
  • Seamless batching via iterators to optimize number of network calls
  • Zero downtime reindexing feature
  • Injectable HTTP client

Version

  • Compatible with Swift 5.0+ and uses latest Swift features such as keypaths, Result type and Codable structures
  • Supports all platforms that Swift supports (iOS, macOS, watchOS, tvOS, Linux)

Related Integrations

  • InstantSearch for iOS
  • Autocomplete

Key links


Get started

INSTALL

1let package = Package(
2    dependencies: [
3        .package(url: "https://github.com/algolia/algoliasearch-client-swift", from: "8.0.0")
4    ],
5    // ...
6)

INDEX

1struct Contact: Encodable {
2  let objectID: ObjectID
3  let firstname: String
4  let lastname: String
5}
6
7let contacts: [Contact] = [
8  .init(objectID: "myID1", firstname: "Jimmie", lastname: "Barninger"),
9  .init(objectID: "myID2", firstname: "Warren", lastname: "Speach"),
10]
11
12let replacements = contacts.map {($0.objectID, $0) }
13
14index.replaceObjects(replacements: replacements) { result in
15  if case .success(let response) = result {
16    print("Response: \(response)")
17  }
18}

SEARCH

1let index = client.index(withName: "contacts")
2index.search(query: "s") { result in
3  if case .success(let response) = result {
4    print("Response: \(response)")
5  }
6}
7
8var query = Query("s")
9query.attributesToRetrieve = ["firstname", "lastname"]
10query.hitsPerPage = 50
11index.search(query: query) { result in
12  if case .success(let response) = result {
13    print("Response: \(response)")
14  }
15}
Get started for freeExplore all developer docs

Built with Algolia

Frontend Tools
Code samples

Ecommerce Starter

Starter for product search powered by Algolia InstantSearch

  • react
  • javascript
  • vue
  • angular
  • nodejs