Search API Client for Swift iOS

Swift

Algolia Search API client for Swift, v1

Sign up

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

Get started

  • Install
    1
    let package = Package(
    2
        dependencies: [
    3
            .package(url: "https://github.com/algolia/algoliasearch-client-swift", from: "8.0.0")
    4
        ],
    5
        // ...
    6
    )
  • Index
    1
    struct Contact: Encodable {
    2
      let objectID: ObjectID
    3
      let firstname: String
    4
      let lastname: String
    5
    }
    6
    7
    let contacts: [Contact] = [
    8
      .init(objectID: "myID1", firstname: "Jimmie", lastname: "Barninger"),
    9
      .init(objectID: "myID2", firstname: "Warren", lastname: "Speach"),
    10
    ]
    11
    12
    let replacements = contacts.map {($0.objectID, $0) }
    13
    14
    index.replaceObjects(replacements: replacements) { result in
    15
      if case .success(let response) = result {
    16
        print("Response: \(response)")
    17
      }
    18
    }
  • Search
    1
    let index = client.index(withName: "contacts")
    2
    index.search(query: "s") { result in
    3
      if case .success(let response) = result {
    4
        print("Response: \(response)")
    5
      }
    6
    }
    7
    8
    var query = Query("s")
    9
    query.attributesToRetrieve = ["firstname", "lastname"]
    10
    query.hitsPerPage = 50
    11
    index.search(query: query) { result in
    12
      if case .success(let response) = result {
    13
        print("Response: \(response)")
    14
      }
    15
    }
Get started for free
Explore developer docs